diff options
49 files changed, 504 insertions, 512 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 50483adde7..847a43ed65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,7 +189,6 @@ set ( -Wnull-dereference \ -Wdouble-promotion \ -Wformat=2 \ - -Wno-unused-parameter \ " ) @@ -212,6 +211,36 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0) endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) + set ( + CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} \ + -Werror \ + -Weverything \ + -Wno-c++98-compat \ + -Wno-c++98-compat-pedantic \ + -Wno-global-constructors \ + -Wno-exit-time-destructors \ + -Wno-shadow \ + -Wno-used-but-marked-unused \ + -Wno-documentation-unknown-command \ + -Wno-weak-vtables \ + -Wno-documentation \ + -Wno-padded \ + -Wno-unused-parameter \ + -Wcovered-switch-default \ + -Wcomma \ + -Wextra-semi \ + -Wzero-as-null-pointer-constant \ + -Wswitch-enum \ + -Wnull-dereference \ + -Wdouble-promotion \ + -Wformat=2 \ + " + ) + endif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0) +endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") # general diff --git a/http/app.h b/http/app.h index dfd5304543..b8103743c3 100644 --- a/http/app.h +++ b/http/app.h @@ -97,13 +97,13 @@ class App #ifdef BMCWEB_ENABLE_SSL if (-1 == socketFd) { - sslServer = std::move(std::make_unique<ssl_server_t>( - this, bindaddrStr, portUint, sslContext, io)); + sslServer = std::make_unique<ssl_server_t>( + this, bindaddrStr, portUint, sslContext, io); } else { - sslServer = std::move( - std::make_unique<ssl_server_t>(this, socketFd, sslContext, io)); + sslServer = + std::make_unique<ssl_server_t>(this, socketFd, sslContext, io); } sslServer->setTickFunction(tickInterval, tickFunction); sslServer->run(); diff --git a/http/common.h b/http/common.h index 77db63c694..95cc763291 100644 --- a/http/common.h +++ b/http/common.h @@ -12,33 +12,6 @@ namespace crow { -inline std::string methodName(boost::beast::http::verb method) -{ - switch (method) - { - case boost::beast::http::verb::delete_: - return "DELETE"; - case boost::beast::http::verb::get: - return "GET"; - case boost::beast::http::verb::head: - return "HEAD"; - case boost::beast::http::verb::post: - return "POST"; - case boost::beast::http::verb::put: - return "PUT"; - case boost::beast::http::verb::connect: - return "CONNECT"; - case boost::beast::http::verb::options: - return "OPTIONS"; - case boost::beast::http::verb::trace: - return "TRACE"; - case boost::beast::http::verb::patch: - return "PATCH"; - default: - return "invalid"; - } -} - enum class ParamType { INT, diff --git a/http/http_client.hpp b/http/http_client.hpp index e6a7db1e04..c455c7bfcf 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -302,8 +302,6 @@ class HttpClient : public std::enable_shared_from_this<HttpClient> sendMessage(data); break; } - default: - break; } } diff --git a/http/http_connection.h b/http/http_connection.h index 609d4a10b1..855cc11bcc 100644 --- a/http/http_connection.h +++ b/http/http_connection.h @@ -176,7 +176,7 @@ class Connection : bool isKeyUsageKeyAgreement = false; ASN1_BIT_STRING* usage = static_cast<ASN1_BIT_STRING*>( - X509_get_ext_d2i(peerCert, NID_key_usage, NULL, NULL)); + X509_get_ext_d2i(peerCert, NID_key_usage, nullptr, nullptr)); if (usage == nullptr) { @@ -208,8 +208,9 @@ class Connection : // Determine that ExtendedKeyUsage includes Client Auth - stack_st_ASN1_OBJECT* extUsage = static_cast<stack_st_ASN1_OBJECT*>( - X509_get_ext_d2i(peerCert, NID_ext_key_usage, NULL, NULL)); + stack_st_ASN1_OBJECT* extUsage = + static_cast<stack_st_ASN1_OBJECT*>(X509_get_ext_d2i( + peerCert, NID_ext_key_usage, nullptr, nullptr)); if (extUsage == nullptr) { @@ -348,7 +349,7 @@ class Connection : if (!isInvalidRequest) { - req->socket = [this, self = shared_from_this()]() -> Adaptor& { + req->socket = [self = shared_from_this()]() -> Adaptor& { return self->socket(); }; diff --git a/http/http_response.h b/http/http_response.h index 7be6b0914c..68e3f2d228 100644 --- a/http/http_response.h +++ b/http/http_response.h @@ -104,7 +104,7 @@ struct Response void preparePayload() { stringResponse->prepare_payload(); - }; + } void clear() { diff --git a/http/http_server.h b/http/http_server.h index c87ddd428c..0099274a82 100644 --- a/http/http_server.h +++ b/http/http_server.h @@ -31,14 +31,14 @@ template <typename Handler, typename Adaptor = boost::asio::ip::tcp::socket> class Server { public: - Server(Handler* handler, std::unique_ptr<tcp::acceptor>&& acceptor, + Server(Handler* handlerIn, std::unique_ptr<tcp::acceptor>&& acceptor, std::shared_ptr<boost::asio::ssl::context> adaptor_ctx, std::shared_ptr<boost::asio::io_context> io = std::make_shared<boost::asio::io_context>()) : ioService(std::move(io)), acceptor(std::move(acceptor)), signals(*ioService, SIGINT, SIGTERM, SIGHUP), tickTimer(*ioService), - timer(*ioService), handler(handler), adaptorCtx(adaptor_ctx) + timer(*ioService), handler(handlerIn), adaptorCtx(adaptor_ctx) {} Server(Handler* handler, const std::string& bindaddr, uint16_t port, @@ -93,7 +93,7 @@ class Server size_t dateStrSz = strftime(&dateStr[0], 99, "%a, %d %b %Y %H:%M:%S GMT", &myTm); dateStr.resize(dateStrSz); - }; + } void run() { diff --git a/http/routing.h b/http/routing.h index 2f90c0752d..1af1b2bc47 100644 --- a/http/routing.h +++ b/http/routing.h @@ -219,7 +219,7 @@ struct Wrapped template <typename Req, typename... Args> struct ReqHandlerWrapper { - ReqHandlerWrapper(Func f) : f(std::move(f)) + ReqHandlerWrapper(Func fIn) : f(std::move(fIn)) {} void operator()(const Request& req, Response& res, Args... args) @@ -315,7 +315,7 @@ class WebSocketRule : public BaseRule using self_t = WebSocketRule; public: - WebSocketRule(std::string rule) : BaseRule(std::move(rule)) + WebSocketRule(std::string ruleIn) : BaseRule(std::move(ruleIn)) {} void validate() override @@ -428,7 +428,7 @@ struct RuleParameterTraits } template <typename... MethodArgs> - self_t& requires(std::initializer_list<const char*> l) + self_t& privileges(std::initializer_list<const char*> l) { self_t* self = static_cast<self_t*>(this); self->privilegesSet.emplace_back(l); @@ -436,7 +436,7 @@ struct RuleParameterTraits } template <typename... MethodArgs> - self_t& requires(const std::vector<redfish::Privileges>& p) + self_t& privileges(const std::vector<redfish::Privileges>& p) { self_t* self = static_cast<self_t*>(this); for (const redfish::Privileges& privilege : p) @@ -450,7 +450,7 @@ struct RuleParameterTraits class DynamicRule : public BaseRule, public RuleParameterTraits<DynamicRule> { public: - DynamicRule(std::string rule) : BaseRule(std::move(rule)) + DynamicRule(std::string ruleIn) : BaseRule(std::move(ruleIn)) {} void validate() override @@ -982,7 +982,7 @@ class Trie case ParamType::PATH: BMCWEB_LOG_DEBUG << "<path>"; break; - default: + case ParamType::MAX: BMCWEB_LOG_DEBUG << "<ERROR>"; break; } @@ -1203,9 +1203,9 @@ class Router // Check to see if this url exists at any verb for (const PerMethod& p : perMethods) { - const std::pair<unsigned, RoutingParams>& found = + const std::pair<unsigned, RoutingParams>& found2 = p.trie.find(req.url); - if (found.first > 0) + if (found2.first > 0) { res.result(boost::beast::http::status::method_not_allowed); res.end(); @@ -1340,7 +1340,7 @@ class Router } } - // Get the user privileges from the role + // Get the userprivileges from the role redfish::Privileges userPrivileges = redfish::getUserPrivileges(userRole); @@ -1349,10 +1349,10 @@ class Router // value from any previous use of this session. req.session->isConfigureSelfOnly = passwordExpired; - // Modify privileges if isConfigureSelfOnly. + // Modifyprivileges if isConfigureSelfOnly. if (req.session->isConfigureSelfOnly) { - // Remove all privileges except ConfigureSelf + // Remove allprivileges except ConfigureSelf userPrivileges = userPrivileges.intersection( redfish::Privileges{"ConfigureSelf"}); BMCWEB_LOG_DEBUG << "Operation limited to ConfigureSelf"; @@ -1384,8 +1384,8 @@ class Router { for (size_t i = 0; i < perMethods.size(); i++) { - BMCWEB_LOG_DEBUG - << methodName(static_cast<boost::beast::http::verb>(i)); + BMCWEB_LOG_DEBUG << boost::beast::http::to_string( + static_cast<boost::beast::http::verb>(i)); perMethods[i].trie.debugPrint(); } } diff --git a/http/utility.h b/http/utility.h index 825409185a..fad212fddd 100644 --- a/http/utility.h +++ b/http/utility.h @@ -39,7 +39,8 @@ class ConstStr } constexpr char operator[](unsigned i) const { - return requiresInRange(i, sizeUint), beginPtr[i]; + requiresInRange(i, sizeUint); + return beginPtr[i]; } constexpr operator const char*() const @@ -760,9 +761,8 @@ inline void escapeHtml(std::string& data) inline void convertToLinks(std::string& s) { // Convert anything with a redfish path into a link - const static std::regex redfishPath{ - "("((.*))"[ \\n]*:[ " - "\\n]*)("((?!")/redfish/.*)")"}; + const std::regex redfishPath{"("((.*))"[ \\n]*:[ " + "\\n]*)("((?!")/redfish/.*)")"}; s = std::regex_replace(s, redfishPath, "$1<a href=\"$5\">$4</a>"); } diff --git a/http/websocket.h b/http/websocket.h index 7670196521..5ec6d0ffd5 100644 --- a/http/websocket.h +++ b/http/websocket.h @@ -22,10 +22,12 @@ struct Connection : std::enable_shared_from_this<Connection> { public: explicit Connection(const crow::Request& reqIn) : - req(reqIn.req), userdataPtr(nullptr){}; + req(reqIn.req), userdataPtr(nullptr) + {} explicit Connection(const crow::Request& reqIn, std::string user) : - req(reqIn.req), userName{std::move(user)}, userdataPtr(nullptr){}; + req(reqIn.req), userName{std::move(user)}, userdataPtr(nullptr) + {} virtual void sendBinary(const std::string_view msg) = 0; virtual void sendBinary(std::string&& msg) = 0; diff --git a/include/async_resp.hpp b/include/async_resp.hpp index f596dcdd20..8267c47617 100644 --- a/include/async_resp.hpp +++ b/include/async_resp.hpp @@ -31,7 +31,7 @@ class AsyncResp } crow::Response& res; - std::function<void()> func = 0; + std::function<void()> func; }; } // namespace bmcweb diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp index 3630ecf0ef..4a5c7c60ea 100644 --- a/include/dbus_monitor.hpp +++ b/include/dbus_monitor.hpp @@ -114,10 +114,10 @@ inline int onPropertyUpdate(sd_bus_message* m, void* userdata, return 0; } -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/subscribe") - .requires({"Login"}) + .privileges({"Login"}) .websocket() .onopen([&](crow::websocket::Connection& conn, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { diff --git a/include/dump_offload.hpp b/include/dump_offload.hpp index 1777dfe72a..bc885cf573 100644 --- a/include/dump_offload.hpp +++ b/include/dump_offload.hpp @@ -31,10 +31,10 @@ static constexpr auto nbdBufferSize = 131088; class Handler : public std::enable_shared_from_this<Handler> { public: - Handler(const std::string& media, boost::asio::io_context& ios, - const std::string& entryID) : + Handler(const std::string& mediaIn, boost::asio::io_context& ios, + const std::string& entryIDIn) : pipeOut(ios), - pipeIn(ios), media(media), entryID(entryID), doingWrite(false), + pipeIn(ios), media(mediaIn), entryID(entryIDIn), doingWrite(false), negotiationDone(false), writeonnbd(false), outputBuffer(std::make_unique< boost::beast::flat_static_buffer<nbdBufferSize>>()), @@ -224,9 +224,9 @@ class Handler : public std::enable_shared_from_this<Handler> boost::asio::async_write( *stream, outputBuffer->data(), - [this](const boost::system::error_code& ec, + [this](const boost::system::error_code& ec2, std::size_t bytes_transferred) { - if (ec) + if (ec2) { BMCWEB_LOG_DEBUG << "Error while writing on socket"; doClose(); diff --git a/include/http_utility.hpp b/include/http_utility.hpp index 88b0247a6a..e0166e338b 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -51,4 +51,4 @@ inline std::string urlEncode(const std::string_view value) return escaped.str(); } -} // namespace http_helpers
\ No newline at end of file +} // namespace http_helpers diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index 7cb744e4b7..db1e9f32b6 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -579,7 +579,7 @@ void requestRoutes(App& app) // allowed only for admin BMCWEB_ROUTE(app, "/ibm/v1/") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { res.jsonValue["@odata.type"] = @@ -597,7 +597,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { handleConfigFileList(res); @@ -605,28 +605,28 @@ void requestRoutes(App& app) BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post)( [](const crow::Request& req, crow::Response& res) { deleteConfigFiles(res); }); BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/<path>") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::put, boost::beast::http::verb::get, boost::beast::http::verb::delete_)( [](const crow::Request& req, crow::Response& res, const std::string& path) { handleFileUrl(req, res, path); }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { getLockServiceData(res); }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post)( [](const crow::Request& req, crow::Response& res) { std::vector<nlohmann::json> body; @@ -640,7 +640,7 @@ void requestRoutes(App& app) handleAcquireLockAPI(req, res, body); }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post)([](const crow::Request& req, crow::Response& res) { std::string type; @@ -670,7 +670,7 @@ void requestRoutes(App& app) } }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post)( [](const crow::Request& req, crow::Response& res) { ListOfSessionIds listSessionIds; @@ -686,7 +686,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post)( [](const crow::Request& req, crow::Response& res) { handleBroadcastService(req, res); diff --git a/include/image_upload.hpp b/include/image_upload.hpp index af7aeac904..a135af952b 100644 --- a/include/image_upload.hpp +++ b/include/image_upload.hpp @@ -16,7 +16,7 @@ namespace crow namespace image_upload { -std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher; +static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher; inline void uploadImageHandler(const crow::Request& req, crow::Response& res, const std::string& filename) @@ -109,10 +109,10 @@ inline void uploadImageHandler(const crow::Request& req, crow::Response& res, timeout.async_wait(timeoutHandler); } -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/upload/image/<str>") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)( [](const crow::Request& req, crow::Response& res, const std::string& filename) { @@ -120,7 +120,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/upload/image") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)( [](const crow::Request& req, crow::Response& res) { uploadImageHandler(req, res, ""); diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp index 4b56f23d67..f83c95b525 100644 --- a/include/kvm_websocket.hpp +++ b/include/kvm_websocket.hpp @@ -16,13 +16,13 @@ static constexpr const uint maxSessions = 4; class KvmSession { public: - explicit KvmSession(crow::websocket::Connection& conn) : - conn(conn), hostSocket(conn.get_io_context()), doingWrite(false) + explicit KvmSession(crow::websocket::Connection& connIn) : + conn(connIn), hostSocket(conn.get_io_context()), doingWrite(false) { boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::make_address("127.0.0.1"), 5900); hostSocket.async_connect( - endpoint, [this, &conn](const boost::system::error_code& ec) { + endpoint, [this, &connIn](const boost::system::error_code& ec) { if (ec) { BMCWEB_LOG_ERROR @@ -30,7 +30,7 @@ class KvmSession << ", Couldn't connect to KVM socket port: " << ec; if (ec != boost::asio::error::operation_aborted) { - conn.close("Error in connecting to KVM port"); + connIn.close("Error in connecting to KVM port"); } return; } @@ -159,7 +159,7 @@ inline void requestRoutes(App& app) sessions.reserve(maxSessions); BMCWEB_ROUTE(app, "/kvm/0") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .websocket() .onopen([](crow::websocket::Connection& conn, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { diff --git a/include/login_routes.hpp b/include/login_routes.hpp index bd335e356f..55a240ea0f 100644 --- a/include/login_routes.hpp +++ b/include/login_routes.hpp @@ -17,7 +17,7 @@ namespace crow namespace login_routes { -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/login") .methods(boost::beast::http::verb::post)([](const crow::Request& req, diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp index af02dde4cf..036fe5a0a2 100644 --- a/include/obmc_console.hpp +++ b/include/obmc_console.hpp @@ -21,7 +21,7 @@ static boost::container::flat_set<crow::websocket::Connection*> sessions; static bool doingWrite = false; -void doWrite() +inline void doWrite() { if (doingWrite) { @@ -59,7 +59,7 @@ void doWrite() }); } -void doRead() +inline void doRead() { BMCWEB_LOG_DEBUG << "Reading from socket"; host_socket->async_read_some( @@ -85,7 +85,7 @@ void doRead() }); } -void connectHandler(const boost::system::error_code& ec) +inline void connectHandler(const boost::system::error_code& ec) { if (ec) { @@ -101,10 +101,10 @@ void connectHandler(const boost::system::error_code& ec) doRead(); } -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/console0") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .websocket() .onopen([](crow::websocket::Connection& conn, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 26904d9aba..57bfc88082 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -36,23 +36,29 @@ using GetSubTreeType = std::vector< std::pair<std::string, std::vector<std::pair<std::string, std::vector<std::string>>>>>; -const char* notFoundMsg = "404 Not Found"; -const char* badReqMsg = "400 Bad Request"; -const char* methodNotAllowedMsg = "405 Method Not Allowed"; -const char* forbiddenMsg = "403 Forbidden"; -const char* methodFailedMsg = "500 Method Call Failed"; -const char* methodOutputFailedMsg = "500 Method Output Error"; -const char* notFoundDesc = +const constexpr char* notFoundMsg = "404 Not Found"; +const constexpr char* badReqMsg = "400 Bad Request"; +const constexpr char* methodNotAllowedMsg = "405 Method Not Allowed"; +const constexpr char* forbiddenMsg = "403 Forbidden"; +const constexpr char* methodFailedMsg = "500 Method Call Failed"; +const constexpr char* methodOutputFailedMsg = "500 Method Output Error"; +const constexpr char* notFoundDesc = "org.freedesktop.DBus.Error.FileNotFound: path or object not found"; -const char* propNotFoundDesc = "The specified property cannot be found"; -const char* noJsonDesc = "No JSON object could be decoded"; -const char* methodNotFoundDesc = "The specified method cannot be found"; -const char* methodNotAllowedDesc = "Method not allowed"; -const char* forbiddenPropDesc = "The specified property cannot be created"; -const char* forbiddenResDesc = "The specified resource cannot be created"; - -void setErrorResponse(crow::Response& res, boost::beast::http::status result, - const std::string& desc, const std::string_view msg) +const constexpr char* propNotFoundDesc = + "The specified property cannot be found"; +const constexpr char* noJsonDesc = "No JSON object could be decoded"; +const constexpr char* methodNotFoundDesc = + "The specified method cannot be found"; +const constexpr char* methodNotAllowedDesc = "Method not allowed"; +const constexpr char* forbiddenPropDesc = + "The specified property cannot be created"; +const constexpr char* forbiddenResDesc = + "The specified resource cannot be created"; + +inline void setErrorResponse(crow::Response& res, + boost::beast::http::status result, + const std::string& desc, + const std::string_view msg) { res.result(result); res.jsonValue = {{"data", {{"description", desc}}}, @@ -60,9 +66,9 @@ void setErrorResponse(crow::Response& res, boost::beast::http::status result, {"status", "error"}}; } -void introspectObjects(const std::string& processName, - const std::string& objectPath, - std::shared_ptr<bmcweb::AsyncResp> transaction) +inline void introspectObjects(const std::string& processName, + const std::string& objectPath, + std::shared_ptr<bmcweb::AsyncResp> transaction) { if (transaction->res.jsonValue.is_null()) { @@ -122,10 +128,9 @@ void introspectObjects(const std::string& processName, "Introspect"); } -void getPropertiesForEnumerate(const std::string& objectPath, - const std::string& service, - const std::string& interface, - std::shared_ptr<bmcweb::AsyncResp> asyncResp) +inline void getPropertiesForEnumerate( + const std::string& objectPath, const std::string& service, + const std::string& interface, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { BMCWEB_LOG_DEBUG << "getPropertiesForEnumerate " << objectPath << " " << service << " " << interface; @@ -163,7 +168,7 @@ void getPropertiesForEnumerate(const std::string& objectPath, // Find any results that weren't picked up by ObjectManagers, to be // called after all ObjectManagers are searched for and called. -void findRemainingObjectsForEnumerate( +inline void findRemainingObjectsForEnumerate( const std::string& objectPath, std::shared_ptr<GetSubTreeType> subtree, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { @@ -196,10 +201,10 @@ void findRemainingObjectsForEnumerate( struct InProgressEnumerateData { - InProgressEnumerateData(const std::string& objectPath, - std::shared_ptr<bmcweb::AsyncResp> asyncResp) : - objectPath(objectPath), - asyncResp(asyncResp) + InProgressEnumerateData(const std::string& objectPathIn, + std::shared_ptr<bmcweb::AsyncResp> asyncRespIn) : + objectPath(objectPathIn), + asyncResp(asyncRespIn) {} ~InProgressEnumerateData() @@ -212,7 +217,7 @@ struct InProgressEnumerateData std::shared_ptr<bmcweb::AsyncResp> asyncResp; }; -void getManagedObjectsForEnumerate( +inline void getManagedObjectsForEnumerate( const std::string& object_name, const std::string& object_manager_path, const std::string& connection_name, std::shared_ptr<InProgressEnumerateData> transaction) @@ -273,7 +278,7 @@ void getManagedObjectsForEnumerate( "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); } -void findObjectManagerPathForEnumerate( +inline void findObjectManagerPathForEnumerate( const std::string& object_name, const std::string& connection_name, std::shared_ptr<InProgressEnumerateData> transaction) { @@ -317,7 +322,8 @@ void findObjectManagerPathForEnumerate( // Uses GetObject to add the object info about the target /enumerate path to // the results of GetSubTree, as GetSubTree will not return info for the // target path, and then continues on enumerating the rest of the tree. -void getObjectAndEnumerate(std::shared_ptr<InProgressEnumerateData> transaction) +inline void + getObjectAndEnumerate(std::shared_ptr<InProgressEnumerateData> transaction) { using GetObjectType = std::vector<std::pair<std::string, std::vector<std::string>>>; @@ -395,7 +401,8 @@ void getObjectAndEnumerate(std::shared_ptr<InProgressEnumerateData> transaction) // Structure for storing data on an in progress action struct InProgressActionData { - InProgressActionData(crow::Response& res) : res(res){}; + InProgressActionData(crow::Response& resIn) : res(resIn) + {} ~InProgressActionData() { // Methods could have been called across different owners @@ -456,7 +463,7 @@ struct InProgressActionData nlohmann::json arguments; }; -std::vector<std::string> dbusArgSplit(const std::string& string) +inline std::vector<std::string> dbusArgSplit(const std::string& string) { std::vector<std::string> ret; if (string.empty()) @@ -504,8 +511,8 @@ std::vector<std::string> dbusArgSplit(const std::string& string) return ret; } -int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, - const nlohmann::json& input_json) +inline int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, + const nlohmann::json& input_json) { int r = 0; BMCWEB_LOG_DEBUG << "Converting " << input_json.dump() @@ -657,11 +664,6 @@ int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, { return -1; } - if ((*intValue < std::numeric_limits<int64_t>::lowest()) || - (*intValue > std::numeric_limits<int64_t>::max())) - { - return -ERANGE; - } r = sd_bus_message_append_basic(m, argCode[0], intValue); if (r < 0) { @@ -675,8 +677,7 @@ int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, { return -1; } - if ((*uintValue < std::numeric_limits<uint8_t>::lowest()) || - (*uintValue > std::numeric_limits<uint8_t>::max())) + if (*uintValue > std::numeric_limits<uint8_t>::max()) { return -ERANGE; } @@ -690,8 +691,7 @@ int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, { return -1; } - if ((*uintValue < std::numeric_limits<uint16_t>::lowest()) || - (*uintValue > std::numeric_limits<uint16_t>::max())) + if (*uintValue > std::numeric_limits<uint16_t>::max()) { return -ERANGE; } @@ -705,8 +705,7 @@ int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, { return -1; } - if ((*uintValue < std::numeric_limits<uint32_t>::lowest()) || - (*uintValue > std::numeric_limits<uint32_t>::max())) + if (*uintValue > std::numeric_limits<uint32_t>::max()) { return -ERANGE; } @@ -720,11 +719,6 @@ int convertJsonToDbus(sd_bus_message* m, const std::string& arg_type, { return -1; } - if ((*uintValue < std::numeric_limits<uint64_t>::lowest()) || - (*uintValue > std::numeric_limits<uint64_t>::max())) - { - return -ERANGE; - } r = sd_bus_message_append_basic(m, argCode[0], uintValue); } else if (argCode == "d") @@ -885,9 +879,9 @@ int readMessageItem(const std::string& typeCode, sdbusplus::message::message& m, int convertDBusToJSON(const std::string& returnType, sdbusplus::message::message& m, nlohmann::json& response); -int readDictEntryFromMessage(const std::string& typeCode, - sdbusplus::message::message& m, - nlohmann::json& object) +inline int readDictEntryFromMessage(const std::string& typeCode, + sdbusplus::message::message& m, + nlohmann::json& object) { std::vector<std::string> types = dbusArgSplit(typeCode); if (types.size() != 2) @@ -944,8 +938,9 @@ int readDictEntryFromMessage(const std::string& typeCode, return 0; } -int readArrayFromMessage(const std::string& typeCode, - sdbusplus::message::message& m, nlohmann::json& data) +inline int readArrayFromMessage(const std::string& typeCode, + sdbusplus::message::message& m, + nlohmann::json& data) { if (typeCode.size() < 2) { @@ -1024,8 +1019,9 @@ int readArrayFromMessage(const std::string& typeCode, return 0; } -int readStructFromMessage(const std::string& typeCode, - sdbusplus::message::message& m, nlohmann::json& data) +inline int readStructFromMessage(const std::string& typeCode, + sdbusplus::message::message& m, + nlohmann::json& data) { if (typeCode.size() < 3) { @@ -1065,7 +1061,8 @@ int readStructFromMessage(const std::string& typeCode, return 0; } -int readVariantFromMessage(sdbusplus::message::message& m, nlohmann::json& data) +inline int readVariantFromMessage(sdbusplus::message::message& m, + nlohmann::json& data) { const char* containerType; int r = sd_bus_message_peek_type(m.get(), nullptr, &containerType); @@ -1100,8 +1097,9 @@ int readVariantFromMessage(sdbusplus::message::message& m, nlohmann::json& data) return 0; } -int convertDBusToJSON(const std::string& returnType, - sdbusplus::message::message& m, nlohmann::json& response) +inline int convertDBusToJSON(const std::string& returnType, + sdbusplus::message::message& m, + nlohmann::json& response) { int r = 0; const std::vector<std::string> returnTypes = dbusArgSplit(returnType); @@ -1256,9 +1254,10 @@ int convertDBusToJSON(const std::string& returnType, return 0; } -void handleMethodResponse(std::shared_ptr<InProgressActionData> transaction, - sdbusplus::message::message& m, - const std::string& returnType) +inline void + handleMethodResponse(std::shared_ptr<InProgressActionData> transaction, + sdbusplus::message::message& m, + const std::string& returnType) { nlohmann::json data; @@ -1320,8 +1319,9 @@ void handleMethodResponse(std::shared_ptr<InProgressActionData> transaction, } } -void findActionOnInterface(std::shared_ptr<InProgressActionData> transaction, - const std::string& connectionName) +inline void + findActionOnInterface(std::shared_ptr<InProgressActionData> transaction, + const std::string& connectionName) { BMCWEB_LOG_DEBUG << "findActionOnInterface for connection " << connectionName; @@ -1444,12 +1444,12 @@ void findActionOnInterface(std::shared_ptr<InProgressActionData> transaction, crow::connections::systemBus->async_send( m, [transaction, returnType]( - boost::system::error_code ec, - sdbusplus::message::message& m) { - if (ec) + boost::system::error_code ec2, + sdbusplus::message::message& m2) { + if (ec2) { transaction->methodFailed = true; - const sd_bus_error* e = m.get_error(); + const sd_bus_error* e = m2.get_error(); if (e) { @@ -1475,7 +1475,7 @@ void findActionOnInterface(std::shared_ptr<InProgressActionData> transaction, transaction->methodPassed = true; } - handleMethodResponse(transaction, m, + handleMethodResponse(transaction, m2, returnType); }); break; @@ -1490,8 +1490,9 @@ void findActionOnInterface(std::shared_ptr<InProgressActionData> transaction, "org.freedesktop.DBus.Introspectable", "Introspect"); } -void handleAction(const crow::Request& req, crow::Response& res, - const std::string& objectPath, const std::string& methodName) +inline void handleAction(const crow::Request& req, crow::Response& res, + const std::string& objectPath, + const std::string& methodName) { BMCWEB_LOG_DEBUG << "handleAction on path: " << objectPath << " and method " << methodName; @@ -1555,8 +1556,8 @@ void handleAction(const crow::Request& req, crow::Response& res, std::array<std::string, 0>()); } -void handleDelete(const crow::Request& req, crow::Response& res, - const std::string& objectPath) +inline void handleDelete(const crow::Request& req, crow::Response& res, + const std::string& objectPath) { BMCWEB_LOG_DEBUG << "handleDelete on path: " << objectPath; @@ -1592,8 +1593,8 @@ void handleDelete(const crow::Request& req, crow::Response& res, std::array<const char*, 0>()); } -void handleList(crow::Response& res, const std::string& objectPath, - int32_t depth = 0) +inline void handleList(crow::Response& res, const std::string& objectPath, + int32_t depth = 0) { crow::connections::systemBus->async_method_call( [&res](const boost::system::error_code ec, @@ -1617,7 +1618,7 @@ void handleList(crow::Response& res, const std::string& objectPath, depth, std::array<std::string, 0>()); } -void handleEnumerate(crow::Response& res, const std::string& objectPath) +inline void handleEnumerate(crow::Response& res, const std::string& objectPath) { BMCWEB_LOG_DEBUG << "Doing enumerate on " << objectPath; auto asyncResp = std::make_shared<bmcweb::AsyncResp>(res); @@ -1655,8 +1656,8 @@ void handleEnumerate(crow::Response& res, const std::string& objectPath) std::array<const char*, 0>()); } -void handleGet(crow::Response& res, std::string& objectPath, - std::string& destProperty) +inline void handleGet(crow::Response& res, std::string& objectPath, + std::string& destProperty) { BMCWEB_LOG_DEBUG << "handleGet: " << objectPath << " prop:" << destProperty; std::shared_ptr<std::string> propertyName = @@ -1681,7 +1682,7 @@ void handleGet(crow::Response& res, std::string& objectPath, std::make_shared<nlohmann::json>(nlohmann::json::object()); // The mapper should never give us an empty interface names // list, but check anyway - for (const std::pair<std::string, std::vector<std::string>> + for (const std::pair<std::string, std::vector<std::string>>& connection : object_names) { const std::vector<std::string>& interfaceNames = @@ -1704,12 +1705,12 @@ void handleGet(crow::Response& res, std::string& objectPath, m.append(interface); crow::connections::systemBus->async_send( m, [&res, response, - propertyName](const boost::system::error_code ec, + propertyName](const boost::system::error_code ec2, sdbusplus::message::message& msg) { - if (ec) + if (ec2) { BMCWEB_LOG_ERROR << "Bad dbus request error: " - << ec; + << ec2; } else { @@ -1770,7 +1771,7 @@ void handleGet(crow::Response& res, std::string& objectPath, struct AsyncPutRequest { - AsyncPutRequest(crow::Response& res) : res(res) + AsyncPutRequest(crow::Response& resIn) : res(resIn) {} ~AsyncPutRequest() { @@ -1795,8 +1796,9 @@ struct AsyncPutRequest nlohmann::json propertyValue; }; -void handlePut(const crow::Request& req, crow::Response& res, - const std::string& objectPath, const std::string& destProperty) +inline void handlePut(const crow::Request& req, crow::Response& res, + const std::string& objectPath, + const std::string& destProperty) { if (destProperty.empty()) { @@ -1835,9 +1837,9 @@ void handlePut(const crow::Request& req, crow::Response& res, std::vector<std::pair<std::string, std::vector<std::string>>>; crow::connections::systemBus->async_method_call( - [transaction](const boost::system::error_code ec, + [transaction](const boost::system::error_code ec2, const GetObjectType& object_names) { - if (!ec && object_names.size() <= 0) + if (!ec2 && object_names.size() <= 0) { setErrorResponse(transaction->res, boost::beast::http::status::not_found, @@ -1845,20 +1847,20 @@ void handlePut(const crow::Request& req, crow::Response& res, return; } - for (const std::pair<std::string, std::vector<std::string>> + for (const std::pair<std::string, std::vector<std::string>>& connection : object_names) { const std::string& connectionName = connection.first; crow::connections::systemBus->async_method_call( [connectionName{std::string(connectionName)}, - transaction](const boost::system::error_code ec, + transaction](const boost::system::error_code ec3, const std::string& introspectXml) { - if (ec) + if (ec3) { BMCWEB_LOG_ERROR << "Introspect call failed with error: " - << ec.message() + << ec3.message() << " on process: " << connectionName; transaction->setErrorStatus("Unexpected Error"); return; @@ -1951,12 +1953,12 @@ void handlePut(const crow::Request& req, crow::Response& res, boost::system::error_code ec, sdbusplus::message::message& - m) { + m2) { BMCWEB_LOG_DEBUG << "sent"; if (ec) { const sd_bus_error* e = - m.get_error(); + m2.get_error(); setErrorResponse( transaction->res, boost::beast::http:: @@ -2072,10 +2074,10 @@ inline void handleDBusUrl(const crow::Request& req, crow::Response& res, res.end(); } -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/bus/") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { res.jsonValue = {{"buses", {{{"name", "system"}}}}, @@ -2084,7 +2086,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/bus/system/") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { auto myCallback = [&res](const boost::system::error_code ec, @@ -2113,14 +2115,14 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/list/") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res) { handleList(res, "/"); }); BMCWEB_ROUTE(app, "/xyz/<path>") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)([](const crow::Request& req, crow::Response& res, const std::string& path) { @@ -2129,7 +2131,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/xyz/<path>") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::put, boost::beast::http::verb::post, boost::beast::http::verb::delete_)( [](const crow::Request& req, crow::Response& res, @@ -2139,7 +2141,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/org/<path>") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)([](const crow::Request& req, crow::Response& res, const std::string& path) { @@ -2148,7 +2150,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/org/<path>") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods(boost::beast::http::verb::put, boost::beast::http::verb::post, boost::beast::http::verb::delete_)( [](const crow::Request& req, crow::Response& res, @@ -2158,7 +2160,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/download/dump/<str>/") - .requires({"ConfigureManager"}) + .privileges({"ConfigureManager"}) .methods(boost::beast::http::verb::get)([](const crow::Request& req, crow::Response& res, const std::string& dumpId) { @@ -2226,7 +2228,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/bus/system/<str>/") - .requires({"Login"}) + .privileges({"Login"}) .methods(boost::beast::http::verb::get)( [](const crow::Request& req, crow::Response& res, @@ -2236,7 +2238,7 @@ void requestRoutes(App& app) }); BMCWEB_ROUTE(app, "/bus/system/<str>/<path>") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .methods( boost::beast::http::verb::get, boost::beast::http::verb::post)([](const crow::Request& req, diff --git a/include/redfish_v1.hpp b/include/redfish_v1.hpp index 429fb084bd..cb7af8f1b8 100644 --- a/include/redfish_v1.hpp +++ b/include/redfish_v1.hpp @@ -6,7 +6,7 @@ namespace crow { namespace redfish { -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/redfish/") .methods(boost::beast::http::verb::get)( diff --git a/include/sessions.hpp b/include/sessions.hpp index 3a787fc129..f0de8c9594 100644 --- a/include/sessions.hpp +++ b/include/sessions.hpp @@ -184,7 +184,7 @@ struct OpenSSLGenerator } return index; - }; + } uint8_t max() { @@ -359,7 +359,7 @@ class SessionStore int64_t getTimeoutInSeconds() const { return std::chrono::seconds(timeoutInMinutes).count(); - }; + } static SessionStore& getInstance() { diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp index 33fadd0dee..d07469eba2 100644 --- a/include/vm_websocket.hpp +++ b/include/vm_websocket.hpp @@ -154,10 +154,10 @@ class Handler : public std::enable_shared_from_this<Handler> static std::shared_ptr<Handler> handler; -void requestRoutes(App& app) +inline void requestRoutes(App& app) { BMCWEB_ROUTE(app, "/vm/0/0") - .requires({"ConfigureComponents", "ConfigureManager"}) + .privileges({"ConfigureComponents", "ConfigureManager"}) .websocket() .onopen([](crow::websocket::Connection& conn, std::shared_ptr<bmcweb::AsyncResp> asyncResp) { diff --git a/include/webassets.hpp b/include/webassets.hpp index 54d3c9814f..7e382d886c 100644 --- a/include/webassets.hpp +++ b/include/webassets.hpp @@ -27,7 +27,7 @@ struct CmpStr } }; -void requestRoutes(App& app) +inline void requestRoutes(App& app) { const static boost::container::flat_map<const char*, const char*, CmpStr> contentTypes{ diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 9c42e06d4e..64c3b7f574 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -48,7 +48,7 @@ static constexpr const char* eventServiceFile = "/var/lib/bmcweb/eventservice_config.json"; #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES -std::shared_ptr<boost::asio::posix::stream_descriptor> inotifyConn = nullptr; +static std::optional<boost::asio::posix::stream_descriptor> inotifyConn; static constexpr const char* redfishEventLogDir = "/var/log"; static constexpr const char* redfishEventLogFile = "/var/log/redfish"; static constexpr const size_t iEventSize = sizeof(inotify_event); @@ -113,8 +113,8 @@ static const Message* formatMessage(const std::string_view& messageID) namespace event_log { -bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, - const bool firstEntry = true) +inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, + const bool firstEntry = true) { static time_t prevTs = 0; static int index = 0; @@ -149,9 +149,9 @@ bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, return true; } -int getEventLogParams(const std::string& logEntry, std::string& timestamp, - std::string& messageID, - std::vector<std::string>& messageArgs) +inline int getEventLogParams(const std::string& logEntry, + std::string& timestamp, std::string& messageID, + std::vector<std::string>& messageArgs) { // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" // First get the Timestamp @@ -195,9 +195,9 @@ int getEventLogParams(const std::string& logEntry, std::string& timestamp, return 0; } -void getRegistryAndMessageKey(const std::string& messageID, - std::string& registryName, - std::string& messageKey) +inline void getRegistryAndMessageKey(const std::string& messageID, + std::string& registryName, + std::string& messageKey) { // Redfish MessageIds are in the form // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find @@ -212,11 +212,12 @@ void getRegistryAndMessageKey(const std::string& messageID, } } -int formatEventLogEntry(const std::string& logEntryID, - const std::string& messageID, - const std::vector<std::string>& messageArgs, - std::string timestamp, const std::string customText, - nlohmann::json& logEntryJson) +inline int formatEventLogEntry(const std::string& logEntryID, + const std::string& messageID, + const std::vector<std::string>& messageArgs, + std::string timestamp, + const std::string customText, + nlohmann::json& logEntryJson) { // Get the Message from the MessageRegistry const message_registries::Message* message = @@ -267,7 +268,7 @@ int formatEventLogEntry(const std::string& logEntryID, } // namespace event_log #endif -bool isFilterQuerySpecialChar(char c) +inline bool isFilterQuerySpecialChar(char c) { switch (c) { @@ -280,10 +281,11 @@ bool isFilterQuerySpecialChar(char c) } } -bool readSSEQueryParams(std::string sseFilter, std::string& formatType, - std::vector<std::string>& messageIds, - std::vector<std::string>& registryPrefixes, - std::vector<std::string>& metricReportDefinitions) +inline bool + readSSEQueryParams(std::string sseFilter, std::string& formatType, + std::vector<std::string>& messageIds, + std::vector<std::string>& registryPrefixes, + std::vector<std::string>& metricReportDefinitions) { sseFilter.erase(std::remove_if(sseFilter.begin(), sseFilter.end(), isFilterQuerySpecialChar), @@ -508,12 +510,12 @@ class Subscription } #endif - void filterAndSendReports(const std::string& id, + void filterAndSendReports(const std::string& id2, const std::string& readingsTs, const ReadingsObjType& readings) { std::string metricReportDef = - "/redfish/v1/TelemetryService/MetricReportDefinitions/" + id; + "/redfish/v1/TelemetryService/MetricReportDefinitions/" + id2; // Empty list means no filter. Send everything. if (metricReportDefinitions.size()) @@ -541,8 +543,8 @@ class Subscription nlohmann::json msg = { {"@odata.id", "/redfish/v1/TelemetryService/MetricReports/" + id}, {"@odata.type", "#MetricReport.v1_3_0.MetricReport"}, - {"Id", id}, - {"Name", id}, + {"Id", id2}, + {"Name", id2}, {"Timestamp", readingsTs}, {"MetricReportDefinition", {{"@odata.id", metricReportDef}}}, {"MetricValues", metricValuesArray}}; @@ -924,7 +926,7 @@ class EventServiceManager std::string addSubscription(const std::shared_ptr<Subscription> subValue, const bool updateFile = true) { - std::srand(static_cast<uint32_t>(std::time(0))); + std::srand(static_cast<uint32_t>(std::time(nullptr))); std::string id; int retry = 3; @@ -937,7 +939,7 @@ class EventServiceManager break; } --retry; - }; + } if (retry <= 0) { @@ -1199,7 +1201,7 @@ class EventServiceManager static void watchRedfishEventLogFile() { - if (inotifyConn == nullptr) + if (inotifyConn) { return; } @@ -1295,8 +1297,7 @@ class EventServiceManager static int startEventLogMonitor(boost::asio::io_context& ioc) { - inotifyConn = - std::make_shared<boost::asio::posix::stream_descriptor>(ioc); + inotifyConn.emplace(ioc); inotifyFd = inotify_init1(IN_NONBLOCK); if (inotifyFd == -1) { @@ -1486,6 +1487,6 @@ class EventServiceManager } return true; } -}; // namespace redfish +}; } // namespace redfish diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp index be098ca8be..b21fba542b 100644 --- a/redfish-core/include/node.hpp +++ b/redfish-core/include/node.hpp @@ -108,7 +108,7 @@ class Node { if (getRule != nullptr) { - getRule->requires(it->second); + getRule->privileges(it->second); } } it = entityPrivileges.find(boost::beast::http::verb::post); @@ -116,7 +116,7 @@ class Node { if (postRule != nullptr) { - postRule->requires(it->second); + postRule->privileges(it->second); } } it = entityPrivileges.find(boost::beast::http::verb::patch); @@ -124,7 +124,7 @@ class Node { if (patchRule != nullptr) { - patchRule->requires(it->second); + patchRule->privileges(it->second); } } it = entityPrivileges.find(boost::beast::http::verb::put); @@ -132,7 +132,7 @@ class Node { if (putRule != nullptr) { - putRule->requires(it->second); + putRule->privileges(it->second); } } it = entityPrivileges.find(boost::beast::http::verb::delete_); @@ -140,7 +140,7 @@ class Node { if (deleteRule != nullptr) { - deleteRule->requires(it->second); + deleteRule->privileges(it->second); } } } diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp index 0282f35ea3..d9bf1fc458 100644 --- a/redfish-core/include/privileges.hpp +++ b/redfish-core/include/privileges.hpp @@ -45,8 +45,9 @@ constexpr const size_t basePrivilegeCount = basePrivileges.size(); constexpr const size_t maxPrivilegeCount = 32; /** @brief A vector of all privilege names and their indexes */ -static const std::vector<std::string> privilegeNames{basePrivileges.begin(), - basePrivileges.end()}; +static const std::array<std::string, maxPrivilegeCount> privilegeNames{ + "Login", "ConfigureManager", "ConfigureComponents", "ConfigureSelf", + "ConfigureUsers"}; /** * @brief Redfish privileges @@ -100,7 +101,7 @@ class Privileges * @return None * */ - bool setSinglePrivilege(const char* privilege) + bool setSinglePrivilege(const std::string_view privilege) { for (size_t searchIndex = 0; searchIndex < privilegeNames.size(); searchIndex++) @@ -116,19 +117,6 @@ class Privileges } /** - * @brief Sets given privilege in the bitset - * - * @param[in] privilege Privilege to be set - * - * @return None - * - */ - bool setSinglePrivilege(const std::string& privilege) - { - return setSinglePrivilege(privilege.c_str()); - } - - /** * @brief Resets the given privilege in the bitset * * @param[in] privilege Privilege to be reset @@ -159,10 +147,10 @@ class Privileges * the setSinglePrivilege is called, or the Privilege structure is destroyed * */ - std::vector<const std::string*> + std::vector<std::string> getActivePrivilegeNames(const PrivilegeType type) const { - std::vector<const std::string*> activePrivileges; + std::vector<std::string> activePrivileges; size_t searchIndex = 0; size_t endIndex = basePrivilegeCount; @@ -176,7 +164,7 @@ class Privileges { if (privilegeBitset.test(searchIndex)) { - activePrivileges.emplace_back(&privilegeNames[searchIndex]); + activePrivileges.emplace_back(privilegeNames[searchIndex]); } } diff --git a/redfish-core/include/server_sent_events.hpp b/redfish-core/include/server_sent_events.hpp index 1c4d2a51fc..9f0da8ff02 100644 --- a/redfish-core/include/server_sent_events.hpp +++ b/redfish-core/include/server_sent_events.hpp @@ -229,6 +229,8 @@ class ServerSentEvents : public std::enable_shared_from_this<ServerSentEvents> case SseConnState::initInProgress: case SseConnState::sendInProgress: case SseConnState::suspended: + case SseConnState::startInit: + case SseConnState::closed: // do nothing break; case SseConnState::initFailed: @@ -245,8 +247,6 @@ class ServerSentEvents : public std::enable_shared_from_this<ServerSentEvents> sendEvent(std::to_string(reqData.first), reqData.second); break; } - default: - break; } return; diff --git a/redfish-core/include/task_messages.hpp b/redfish-core/include/task_messages.hpp index 050cc63c56..33c2db54bc 100644 --- a/redfish-core/include/task_messages.hpp +++ b/redfish-core/include/task_messages.hpp @@ -20,7 +20,7 @@ namespace redfish namespace messages { -nlohmann::json taskAborted(const std::string& arg1) +inline nlohmann::json taskAborted(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -31,7 +31,7 @@ nlohmann::json taskAborted(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskCancelled(const std::string& arg1) +inline nlohmann::json taskCancelled(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -42,7 +42,7 @@ nlohmann::json taskCancelled(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskCompletedOK(const std::string& arg1) +inline nlohmann::json taskCompletedOK(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -53,7 +53,7 @@ nlohmann::json taskCompletedOK(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskCompletedWarning(const std::string& arg1) +inline nlohmann::json taskCompletedWarning(const std::string& arg1) { return nlohmann::json{{"@odata.type", "#Message.v1_0_0.Message"}, {"MessageId", "TaskEvent.1.0.1.TaskCompletedWarning"}, @@ -64,7 +64,7 @@ nlohmann::json taskCompletedWarning(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskPaused(const std::string& arg1) +inline nlohmann::json taskPaused(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -75,7 +75,8 @@ nlohmann::json taskPaused(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskProgressChanged(const std::string& arg1, const size_t arg2) +inline nlohmann::json taskProgressChanged(const std::string& arg1, + const size_t arg2) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -87,7 +88,7 @@ nlohmann::json taskProgressChanged(const std::string& arg1, const size_t arg2) {"Resolution", "None."}}; } -nlohmann::json taskRemoved(const std::string& arg1) +inline nlohmann::json taskRemoved(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -98,7 +99,7 @@ nlohmann::json taskRemoved(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskResumed(const std::string& arg1) +inline nlohmann::json taskResumed(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, @@ -109,7 +110,7 @@ nlohmann::json taskResumed(const std::string& arg1) {"Resolution", "None."}}; } -nlohmann::json taskStarted(const std::string& arg1) +inline nlohmann::json taskStarted(const std::string& arg1) { return nlohmann::json{ {"@odata.type", "#Message.v1_0_0.Message"}, diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp index 95d684fccc..65f19ca08b 100644 --- a/redfish-core/include/utils/fw_utils.hpp +++ b/redfish-core/include/utils/fw_utils.hpp @@ -28,10 +28,10 @@ constexpr const char* bmcPurpose = * * @return void */ -void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp, - const std::string& fwVersionPurpose, - const std::string& activeVersionPropName, - const bool populateLinkToActiveImage) +inline void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp, + const std::string& fwVersionPurpose, + const std::string& activeVersionPropName, + const bool populateLinkToActiveImage) { // Get active FW images crow::connections::systemBus->async_method_call( @@ -80,13 +80,13 @@ void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp, crow::connections::systemBus->async_method_call( [aResp, fw, swId, fwVersionPurpose, activeVersionPropName, populateLinkToActiveImage]( - const boost::system::error_code ec, + const boost::system::error_code ec2, const std::vector<std::pair< std::string, std::vector<std::string>>>& objInfo) { - if (ec) + if (ec2) { - BMCWEB_LOG_DEBUG << "error_code = " << ec; - BMCWEB_LOG_DEBUG << "error msg = " << ec.message(); + BMCWEB_LOG_DEBUG << "error_code = " << ec2; + BMCWEB_LOG_DEBUG << "error msg = " << ec2.message(); messages::internalError(aResp->res); return; } @@ -116,16 +116,16 @@ void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp, crow::connections::systemBus->async_method_call( [aResp, swId, fwVersionPurpose, activeVersionPropName, populateLinkToActiveImage]( - const boost::system::error_code ec, + const boost::system::error_code ec3, const boost::container::flat_map< std::string, std::variant<bool, std::string, uint64_t, uint32_t>>& propertiesList) { - if (ec) + if (ec3) { - BMCWEB_LOG_ERROR << "error_code = " << ec; + BMCWEB_LOG_ERROR << "error_code = " << ec3; BMCWEB_LOG_ERROR << "error msg = " - << ec.message(); + << ec3.message(); messages::internalError(aResp->res); return; } @@ -230,7 +230,7 @@ void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp, * * @return The corresponding Redfish state */ -std::string getRedfishFWState(const std::string& fwState) +inline std::string getRedfishFWState(const std::string& fwState) { if (fwState == "xyz.openbmc_project.Software.Activation.Activations.Active") { @@ -262,7 +262,7 @@ std::string getRedfishFWState(const std::string& fwState) * * @return The corresponding Redfish health state */ -std::string getRedfishFWHealth(const std::string& fwState) +inline std::string getRedfishFWHealth(const std::string& fwState) { if ((fwState == "xyz.openbmc_project.Software.Activation.Activations.Active") || @@ -292,9 +292,9 @@ std::string getRedfishFWHealth(const std::string& fwState) * * @return void */ -void getFwStatus(std::shared_ptr<AsyncResp> asyncResp, - const std::shared_ptr<std::string> swId, - const std::string& dbusSvc) +inline void getFwStatus(std::shared_ptr<AsyncResp> asyncResp, + const std::shared_ptr<std::string> swId, + const std::string& dbusSvc) { BMCWEB_LOG_DEBUG << "getFwStatus: swId " << *swId << " svc " << dbusSvc; @@ -350,8 +350,8 @@ void getFwStatus(std::shared_ptr<AsyncResp> asyncResp, * @param[i,o] asyncResp Async response object * @param[i] fwId The firmware ID */ -void getFwUpdateableStatus(std::shared_ptr<AsyncResp> asyncResp, - const std::shared_ptr<std::string> fwId) +inline void getFwUpdateableStatus(std::shared_ptr<AsyncResp> asyncResp, + const std::shared_ptr<std::string> fwId) { crow::connections::systemBus->async_method_call( [asyncResp, fwId](const boost::system::error_code ec, diff --git a/redfish-core/include/utils/systemd_utils.hpp b/redfish-core/include/utils/systemd_utils.hpp index da1b4e25bc..0db1d94000 100644 --- a/redfish-core/include/utils/systemd_utils.hpp +++ b/redfish-core/include/utils/systemd_utils.hpp @@ -29,7 +29,7 @@ namespace systemd_utils * @return Service root UUID */ -const std::string getUuid() +inline const std::string getUuid() { std::string ret; // This ID needs to match the one in ipmid diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 052214985d..b8517b4a35 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -27,7 +27,7 @@ namespace redfish { -constexpr const char* ldapConfigObject = +constexpr const char* ldapConfigObjectName = "/xyz/openbmc_project/user/ldap/openldap"; constexpr const char* ADConfigObject = "/xyz/openbmc_project/user/ldap/active_directory"; @@ -118,10 +118,10 @@ inline std::string getPrivilegeFromRoleId(std::string_view role) return ""; } -void userErrorMessageHandler(const sd_bus_error* e, - std::shared_ptr<AsyncResp> asyncResp, - const std::string& newUser, - const std::string& username) +inline void userErrorMessageHandler(const sd_bus_error* e, + std::shared_ptr<AsyncResp> asyncResp, + const std::string& newUser, + const std::string& username) { const char* errorMessage = e->name; if (e == nullptr) @@ -166,9 +166,9 @@ void userErrorMessageHandler(const sd_bus_error* e, return; } -void parseLDAPConfigData(nlohmann::json& json_response, - const LDAPConfigData& confData, - const std::string& ldapType) +inline void parseLDAPConfigData(nlohmann::json& json_response, + const LDAPConfigData& confData, + const std::string& ldapType) { std::string service = (ldapType == "LDAP") ? "LDAPService" : "ActiveDirectoryService"; @@ -207,7 +207,7 @@ void parseLDAPConfigData(nlohmann::json& json_response, * create, to delete or to set Rolemapping object based on the given input. * */ -static void handleRoleMapPatch( +inline void handleRoleMapPatch( const std::shared_ptr<AsyncResp>& asyncResp, const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, const std::string& serverType, std::vector<nlohmann::json>& input) @@ -344,7 +344,7 @@ static void handleRoleMapPatch( } else if (serverType == "LDAP") { - dbusObjectPath = ldapConfigObject; + dbusObjectPath = ldapConfigObjectName; } BMCWEB_LOG_DEBUG << "Remote Group=" << *remoteGroup @@ -389,13 +389,13 @@ inline void getLDAPConfigData(const std::string& ldapType, crow::connections::systemBus->async_method_call( [callback, ldapType](const boost::system::error_code ec, const GetObjectType& resp) { - LDAPConfigData confData{}; if (ec || resp.empty()) { BMCWEB_LOG_ERROR << "DBUS response error during getting of " "service name: " << ec; - callback(false, confData, ldapType); + LDAPConfigData empty{}; + callback(false, empty, ldapType); return; } std::string service = resp.begin()->first; @@ -551,14 +551,13 @@ inline void getLDAPConfigData(const std::string& ldapType, "GetManagedObjects"); }, mapperBusName, mapperObjectPath, mapperIntf, "GetObject", - ldapConfigObject, interfaces); + ldapConfigObjectName, interfaces); } class AccountService : public Node { public: - AccountService(App& app) : - Node(app, "/redfish/v1/AccountService/"), app(app) + AccountService(App& app) : Node(app, "/redfish/v1/AccountService/") { entityPrivileges = { {boost::beast::http::verb::get, {{"Login"}}}, @@ -977,7 +976,7 @@ class AccountService : public Node } else if (serverType == "LDAP") { - dbusObjectPath = ldapConfigObject; + dbusObjectPath = ldapConfigObjectName; } std::optional<nlohmann::json> authentication; @@ -1045,51 +1044,51 @@ class AccountService : public Node serviceEnabled, dbusObjectPath, remoteRoleMapData]( bool success, LDAPConfigData confData, - const std::string& serverType) { + const std::string& serverT) { if (!success) { messages::internalError(asyncResp->res); return; } - parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverType); + parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT); if (confData.serviceEnabled) { // Disable the service first and update the rest of // the properties. - handleServiceEnablePatch(false, asyncResp, serverType, + handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath); } if (serviceAddressList) { handleServiceAddressPatch(*serviceAddressList, asyncResp, - serverType, dbusObjectPath); + serverT, dbusObjectPath); } if (userName) { - handleUserNamePatch(*userName, asyncResp, serverType, + handleUserNamePatch(*userName, asyncResp, serverT, dbusObjectPath); } if (password) { - handlePasswordPatch(*password, asyncResp, serverType, + handlePasswordPatch(*password, asyncResp, serverT, dbusObjectPath); } if (baseDNList) { - handleBaseDNPatch(*baseDNList, asyncResp, serverType, + handleBaseDNPatch(*baseDNList, asyncResp, serverT, dbusObjectPath); } if (userNameAttribute) { - handleUserNameAttrPatch(*userNameAttribute, asyncResp, - serverType, dbusObjectPath); + handleUserNameAttrPatch(*userNameAttribute, asyncResp, serverT, + dbusObjectPath); } if (groupsAttribute) { - handleGroupNameAttrPatch(*groupsAttribute, asyncResp, - serverType, dbusObjectPath); + handleGroupNameAttrPatch(*groupsAttribute, asyncResp, serverT, + dbusObjectPath); } if (serviceEnabled) { @@ -1099,7 +1098,7 @@ class AccountService : public Node if (*serviceEnabled) { handleServiceEnablePatch(*serviceEnabled, asyncResp, - serverType, dbusObjectPath); + serverT, dbusObjectPath); } } else @@ -1108,7 +1107,7 @@ class AccountService : public Node // then revert it to the same state as it was // before. handleServiceEnablePatch(confData.serviceEnabled, asyncResp, - serverType, dbusObjectPath); + serverT, dbusObjectPath); } if (remoteRoleMapData) @@ -1116,8 +1115,8 @@ class AccountService : public Node std::vector<nlohmann::json> remoteRoleMap = std::move(*remoteRoleMapData); - handleRoleMapPatch(asyncResp, confData.groupRoleList, - serverType, remoteRoleMap); + handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT, + remoteRoleMap); } }); } @@ -1312,8 +1311,6 @@ class AccountService : public Node std::variant<uint16_t>(*lockoutThreshold)); } } - - App& app; }; class AccountsCollection : public Node @@ -1453,9 +1450,9 @@ class AccountsCollection : public Node crow::connections::systemBus->async_method_call( [asyncResp, username, password{std::move(password)}]( - const boost::system::error_code ec, + const boost::system::error_code ec2, sdbusplus::message::message& m) { - if (ec) + if (ec2) { userErrorMessageHandler(m.get_error(), asyncResp, username, ""); @@ -1469,9 +1466,9 @@ class AccountsCollection : public Node // but the password set failed.Something is wrong, // so delete the user that we've already created crow::connections::systemBus->async_method_call( - [asyncResp, - password](const boost::system::error_code ec) { - if (ec) + [asyncResp, password]( + const boost::system::error_code ec3) { + if (ec3) { messages::internalError(asyncResp->res); return; diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index 6ade4e5e3a..e237fd35f2 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -97,7 +97,7 @@ class CertificateService : public Node * @param[in] path URL * @return -1 on failure and number on success */ -long getIDFromURL(const std::string_view url) +inline long getIDFromURL(const std::string_view url) { std::size_t found = url.rfind("/"); if (found == std::string::npos) @@ -115,7 +115,7 @@ long getIDFromURL(const std::string_view url) return -1; } -std::string +inline std::string getCertificateFromReqBody(const std::shared_ptr<AsyncResp>& asyncResp, const crow::Request& req) { @@ -180,11 +180,9 @@ class CertificateFile if (std::filesystem::exists(certDirectory)) { BMCWEB_LOG_DEBUG << "Removing certificate file" << certificateFile; - try - { - std::filesystem::remove_all(certDirectory); - } - catch (const std::filesystem::filesystem_error& e) + std::error_code ec; + std::filesystem::remove_all(certDirectory, ec); + if (ec) { BMCWEB_LOG_ERROR << "Failed to remove temp directory" << certDirectory; diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index ce0a8c1269..10b07980e0 100644 --- a/redfish-core/lib/chassis.hpp +++ b/redfish-core/lib/chassis.hpp @@ -33,7 +33,7 @@ namespace redfish * * @return None. */ -void getChassisState(std::shared_ptr<AsyncResp> aResp) +inline void getChassisState(std::shared_ptr<AsyncResp> aResp) { crow::connections::systemBus->async_method_call( [aResp{std::move(aResp)}]( @@ -85,9 +85,9 @@ using ManagedObjectsType = std::vector<std::pair< using PropertiesType = boost::container::flat_map<std::string, VariantType>; -void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, - const std::string& service, - const std::string& objPath) +inline void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, + const std::string& service, + const std::string& objPath) { BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; @@ -120,7 +120,7 @@ void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, /** * Retrieves physical security properties over dbus */ -void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp) +inline void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp) { crow::connections::systemBus->async_method_call( [aResp{std::move(aResp)}]( @@ -289,9 +289,9 @@ class Chassis : public Node auto health = std::make_shared<HealthPopulate>(asyncResp); crow::connections::systemBus->async_method_call( - [health](const boost::system::error_code ec, + [health](const boost::system::error_code ec2, std::variant<std::vector<std::string>>& resp) { - if (ec) + if (ec2) { return; // no sensors = no failures } @@ -335,7 +335,7 @@ class Chassis : public Node const std::string& connectionName = connectionNames[0].first; - const std::vector<std::string>& interfaces = + const std::vector<std::string>& interfaces2 = connectionNames[0].second; const std::array<const char*, 2> hasIndicatorLed = { "xyz.openbmc_project.Inventory.Item.Panel", @@ -343,8 +343,8 @@ class Chassis : public Node for (const char* interface : hasIndicatorLed) { - if (std::find(interfaces.begin(), interfaces.end(), - interface) != interfaces.end()) + if (std::find(interfaces2.begin(), interfaces2.end(), + interface) != interfaces2.end()) { getIndicatorLedState(asyncResp); break; @@ -353,7 +353,7 @@ class Chassis : public Node crow::connections::systemBus->async_method_call( [asyncResp, chassisId(std::string(chassisId))]( - const boost::system::error_code ec, + const boost::system::error_code ec2, const std::vector<std::pair< std::string, VariantType>>& propertiesList) { for (const std::pair<std::string, VariantType>& @@ -480,7 +480,7 @@ class Chassis : public Node continue; } - const std::vector<std::string>& interfaces = + const std::vector<std::string>& interfaces3 = connectionNames[0].second; if (indicatorLed) @@ -492,8 +492,9 @@ class Chassis : public Node bool indicatorChassis = false; for (const char* interface : hasIndicatorLed) { - if (std::find(interfaces.begin(), interfaces.end(), - interface) != interfaces.end()) + if (std::find(interfaces3.begin(), + interfaces3.end(), + interface) != interfaces3.end()) { indicatorChassis = true; break; @@ -523,7 +524,7 @@ class Chassis : public Node } }; -void doChassisPowerCycle(std::shared_ptr<AsyncResp> asyncResp) +inline void doChassisPowerCycle(std::shared_ptr<AsyncResp> asyncResp) { const char* processName = "xyz.openbmc_project.State.Chassis"; const char* objectPath = "/xyz/openbmc_project/state/chassis0"; diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp index 0510f2b611..b4178b41bc 100644 --- a/redfish-core/lib/cpudimm.hpp +++ b/redfish-core/lib/cpudimm.hpp @@ -29,9 +29,9 @@ using InterfacesProperties = boost::container::flat_map< std::string, boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; -void getResourceList(std::shared_ptr<AsyncResp> aResp, - const std::string& subclass, - const std::vector<const char*>& collectionName) +inline void getResourceList(std::shared_ptr<AsyncResp> aResp, + const std::string& subclass, + const std::vector<const char*>& collectionName) { BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources."; crow::connections::systemBus->async_method_call( @@ -69,8 +69,9 @@ void getResourceList(std::shared_ptr<AsyncResp> aResp, "/xyz/openbmc_project/inventory", 0, collectionName); } -void getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, - const InterfacesProperties& cpuInterfacesProperties) +inline void + getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, + const InterfacesProperties& cpuInterfacesProperties) { BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; @@ -193,9 +194,10 @@ void getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, return; } -void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, - const std::string& cpuId, const std::string& service, - const std::string& objPath) +inline void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, + const std::string& cpuId, + const std::string& service, + const std::string& objPath) { BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; @@ -263,8 +265,9 @@ void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); } -void getCpuAssetData(std::shared_ptr<AsyncResp> aResp, - const std::string& service, const std::string& objPath) +inline void getCpuAssetData(std::shared_ptr<AsyncResp> aResp, + const std::string& service, + const std::string& objPath) { BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; crow::connections::systemBus->async_method_call( @@ -306,10 +309,10 @@ void getCpuAssetData(std::shared_ptr<AsyncResp> aResp, "xyz.openbmc_project.Inventory.Decorator.Asset"); } -void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, - const std::string& acclrtrId, - const std::string& service, - const std::string& objPath) +inline void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, + const std::string& acclrtrId, + const std::string& service, + const std::string& objPath) { BMCWEB_LOG_DEBUG << "Get available system Accelerator resources by service."; @@ -365,8 +368,9 @@ void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); } -void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string& cpuId, - const std::vector<const char*> inventoryItems) +inline void getCpuData(std::shared_ptr<AsyncResp> aResp, + const std::string& cpuId, + const std::vector<const char*> inventoryItems) { BMCWEB_LOG_DEBUG << "Get available system cpu resources."; @@ -891,8 +895,9 @@ void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); } -void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, - const std::string& service, const std::string& path) +inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, + const std::string& service, + const std::string& path) { crow::connections::systemBus->async_method_call( [aResp{std::move(aResp)}]( @@ -958,7 +963,8 @@ void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"); } -void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string& dimmId) +inline void getDimmData(std::shared_ptr<AsyncResp> aResp, + const std::string& dimmId) { BMCWEB_LOG_DEBUG << "Get available system dimm resources."; crow::connections::systemBus->async_method_call( diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index a47d4b1052..852b3b72c4 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -669,9 +669,9 @@ inline bool ipv4VerifyIpAndGetBitcount(const std::string& ip, firstZeroInByteHit = false; // Count bits - for (int bitIdx = 7; bitIdx >= 0; bitIdx--) + for (long bitIdx = 7; bitIdx >= 0; bitIdx--) { - if (value & (1 << bitIdx)) + if (value & (1L << bitIdx)) { if (firstZeroInByteHit) { @@ -777,8 +777,8 @@ inline void deleteAndCreateIPv4(const std::string& ifaceId, messages::internalError(asyncResp->res); } crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec) { - if (ec) + [asyncResp](const boost::system::error_code ec2) { + if (ec2) { messages::internalError(asyncResp->res); } @@ -843,8 +843,8 @@ inline void deleteAndCreateIPv6(const std::string& ifaceId, messages::internalError(asyncResp->res); } crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec) { - if (ec) + [asyncResp](const boost::system::error_code ec2) { + if (ec2) { messages::internalError(asyncResp->res); } diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp index 26cd80a665..fa06fcf0b8 100644 --- a/redfish-core/lib/event_service.hpp +++ b/redfish-core/lib/event_service.hpp @@ -233,7 +233,7 @@ class EventDestinationCollection : public Node std::string protocol; std::optional<std::string> context; std::optional<std::string> subscriptionType; - std::optional<std::string> eventFormatType; + std::optional<std::string> eventFormatType2; std::optional<std::string> retryPolicy; std::optional<std::vector<std::string>> msgIds; std::optional<std::vector<std::string>> regPrefixes; @@ -244,7 +244,7 @@ class EventDestinationCollection : public Node if (!json_util::readJson( req, res, "Destination", destUrl, "Context", context, "Protocol", protocol, "SubscriptionType", subscriptionType, - "EventFormatType", eventFormatType, "HttpHeaders", headers, + "EventFormatType", eventFormatType2, "HttpHeaders", headers, "RegistryPrefixes", regPrefixes, "MessageIds", msgIds, "DeliveryRetryPolicy", retryPolicy, "MetricReportDefinitions", mrdJsonArray, "ResourceTypes", resTypes)) @@ -328,22 +328,22 @@ class EventDestinationCollection : public Node } subValue->protocol = protocol; - if (eventFormatType) + if (eventFormatType2) { if (std::find(supportedEvtFormatTypes.begin(), supportedEvtFormatTypes.end(), - *eventFormatType) == supportedEvtFormatTypes.end()) + *eventFormatType2) == supportedEvtFormatTypes.end()) { messages::propertyValueNotInList( - asyncResp->res, *eventFormatType, "EventFormatType"); + asyncResp->res, *eventFormatType2, "EventFormatType"); return; } - subValue->eventFormatType = *eventFormatType; + subValue->eventFormatType = *eventFormatType2; } else { // If not specified, use default "Event" - subValue->eventFormatType.assign({"Event"}); + subValue->eventFormatType = "Event"; } if (context) @@ -522,7 +522,7 @@ class EventServiceSSE : public Node else { // If nothing specified, using default "Event" - subValue->eventFormatType.assign({"Event"}); + subValue->eventFormatType = "Event"; } if (!subValue->registryPrefixes.empty()) diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp index 59c8a27a5c..4f21b3e438 100644 --- a/redfish-core/lib/health.hpp +++ b/redfish-core/lib/health.hpp @@ -28,13 +28,13 @@ namespace redfish struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> { - HealthPopulate(const std::shared_ptr<AsyncResp>& asyncResp) : - asyncResp(asyncResp), jsonStatus(asyncResp->res.jsonValue["Status"]) + HealthPopulate(const std::shared_ptr<AsyncResp>& asyncRespIn) : + asyncResp(asyncRespIn), jsonStatus(asyncResp->res.jsonValue["Status"]) {} - HealthPopulate(const std::shared_ptr<AsyncResp>& asyncResp, + HealthPopulate(const std::shared_ptr<AsyncResp>& asyncRespIn, nlohmann::json& status) : - asyncResp(asyncResp), + asyncResp(asyncRespIn), jsonStatus(status) {} @@ -46,10 +46,10 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> health = "OK"; rollup = "OK"; - for (const std::shared_ptr<HealthPopulate>& health : children) + for (const std::shared_ptr<HealthPopulate>& healthChild : children) { - health->globalInventoryPath = globalInventoryPath; - health->statuses = statuses; + healthChild->globalInventoryPath = globalInventoryPath; + healthChild->statuses = statuses; } for (const auto& [path, interfaces] : statuses) @@ -232,4 +232,4 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> std::string globalInventoryPath = "-"; // default to illegal dbus path bool populated = false; }; -} // namespace redfish
\ No newline at end of file +} // namespace redfish diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp index 25248f8979..a2a5bc9bc7 100644 --- a/redfish-core/lib/led.hpp +++ b/redfish-core/lib/led.hpp @@ -30,7 +30,7 @@ namespace redfish * * @return None. */ -void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) +inline void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get led groups"; crow::connections::systemBus->async_method_call( @@ -55,11 +55,11 @@ void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) } } crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec, - const std::variant<bool> asserted) { - if (!ec) + [aResp](const boost::system::error_code ec2, + const std::variant<bool> asserted2) { + if (!ec2) { - const bool* ledOn = std::get_if<bool>(&asserted); + const bool* ledOn = std::get_if<bool>(&asserted2); if (!ledOn) { BMCWEB_LOG_DEBUG @@ -98,8 +98,8 @@ void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) * * @return None. */ -void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, - const std::string& ledState) +inline void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, + const std::string& ledState) { BMCWEB_LOG_DEBUG << "Set led groups"; bool ledOn = false; @@ -133,11 +133,11 @@ void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, } } crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec, - const std::variant<bool> asserted) { - if (ec) + [aResp](const boost::system::error_code ec2, + const std::variant<bool> asserted2) { + if (ec2) { - BMCWEB_LOG_DEBUG << "DBUS response error " << ec; + BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; messages::internalError(aResp->res); return; } @@ -154,4 +154,4 @@ void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, "xyz.openbmc_project.Led.Group", "Asserted", std::variant<bool>(ledBlinkng)); } -} // namespace redfish
\ No newline at end of file +} // namespace redfish diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index a884290ff0..a4a873a28e 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -989,13 +989,13 @@ class SystemLogServiceCollection : public Node { if (pathStr.find("PostCode") != std::string::npos) { - nlohmann::json& logServiceArray = + nlohmann::json& logServiceArrayLocal = asyncResp->res.jsonValue["Members"]; - logServiceArray.push_back( + logServiceArrayLocal.push_back( {{"@odata.id", "/redfish/v1/Systems/system/" "LogServices/PostCodes"}}); asyncResp->res.jsonValue["Members@odata.count"] = - logServiceArray.size(); + logServiceArrayLocal.size(); return; } } @@ -1152,7 +1152,7 @@ static int fillEventLogEntryJson(const std::string& logEntryID, messageArgsSize = logEntryFields.size() - 1; } - messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); + messageArgs = {&messageArgsStart, messageArgsSize}; // Fill the MessageArgs into the Message int i = 0; @@ -3476,8 +3476,8 @@ class PostCodesEntry : public Node codeIndexStr.remove_prefix(dashPos + 1); bootIndex = static_cast<uint16_t>( - strtoul(std::string(bootIndexStr).c_str(), NULL, 0)); - codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0); + strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); + codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); if (bootIndex == 0 || codeIndex == 0) { BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index 552c264d0b..a113ba169f 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -38,7 +38,7 @@ namespace redfish * * @param[in] asyncResp - Shared pointer for completing asynchronous calls */ -void doBMCGracefulRestart(std::shared_ptr<AsyncResp> asyncResp) +inline void doBMCGracefulRestart(std::shared_ptr<AsyncResp> asyncResp) { const char* processName = "xyz.openbmc_project.State.BMC"; const char* objectPath = "/xyz/openbmc_project/state/bmc0"; @@ -238,7 +238,7 @@ static constexpr const char* stepwiseConfigurationIface = static constexpr const char* thermalModeIface = "xyz.openbmc_project.Control.ThermalMode"; -static void asyncPopulatePid(const std::string& connection, +inline void asyncPopulatePid(const std::string& connection, const std::string& path, const std::string& currentProfile, const std::vector<std::string>& supportedProfiles, @@ -655,7 +655,7 @@ enum class CreatePIDRet patch }; -static bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response, +inline bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response, std::vector<nlohmann::json>& config, std::vector<std::string>& zones) { @@ -693,7 +693,7 @@ static bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response, return true; } -static const dbus::utility::ManagedItem* +inline const dbus::utility::ManagedItem* findChassis(const dbus::utility::ManagedObjectType& managedObj, const std::string& value, std::string& chassis) { @@ -725,7 +725,7 @@ static const dbus::utility::ManagedItem* return nullptr; } -static CreatePIDRet createPidInterface( +inline CreatePIDRet createPidInterface( const std::shared_ptr<AsyncResp>& response, const std::string& type, nlohmann::json::iterator it, const std::string& path, const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, @@ -1052,10 +1052,10 @@ static CreatePIDRet createPidInterface( for (auto& step : *steps) { double target; - double output; + double out; if (!redfish::json_util::readJson(step, response->res, "Target", - target, "Output", output)) + target, "Output", out)) { BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " @@ -1063,7 +1063,7 @@ static CreatePIDRet createPidInterface( return CreatePIDRet::fail; } readings.emplace_back(target); - outputs.emplace_back(output); + outputs.emplace_back(out); } output["Reading"] = std::move(readings); output["Output"] = std::move(outputs); @@ -1109,8 +1109,8 @@ static CreatePIDRet createPidInterface( struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> { - GetPIDValues(const std::shared_ptr<AsyncResp>& asyncResp) : - asyncResp(asyncResp) + GetPIDValues(const std::shared_ptr<AsyncResp>& asyncRespIn) : + asyncResp(asyncRespIn) {} @@ -1121,14 +1121,14 @@ struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> // get all configurations crow::connections::systemBus->async_method_call( [self](const boost::system::error_code ec, - const crow::openbmc_mapper::GetSubTreeType& subtree) { + const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) { if (ec) { BMCWEB_LOG_ERROR << ec; messages::internalError(self->asyncResp->res); return; } - self->subtree = subtree; + self->subtree = subtreeLocal; }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", @@ -1140,12 +1140,12 @@ struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> // at the same time get the selected profile crow::connections::systemBus->async_method_call( [self](const boost::system::error_code ec, - const crow::openbmc_mapper::GetSubTreeType& subtree) { - if (ec || subtree.empty()) + const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) { + if (ec || subtreeLocal.empty()) { return; } - if (subtree[0].second.size() != 1) + if (subtreeLocal[0].second.size() != 1) { // invalid mapper response, should never happen BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; @@ -1153,15 +1153,15 @@ struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> return; } - const std::string& path = subtree[0].first; - const std::string& owner = subtree[0].second[0].first; + const std::string& path = subtreeLocal[0].first; + const std::string& owner = subtreeLocal[0].second[0].first; crow::connections::systemBus->async_method_call( [path, owner, self]( - const boost::system::error_code ec, + const boost::system::error_code ec2, const boost::container::flat_map< std::string, std::variant<std::vector<std::string>, std::string>>& resp) { - if (ec) + if (ec2) { BMCWEB_LOG_ERROR << "GetPIDValues: Can't get " "thermalModeIface " diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp index 3e48efb113..4d612fc037 100644 --- a/redfish-core/lib/network_protocol.hpp +++ b/redfish-core/lib/network_protocol.hpp @@ -452,9 +452,8 @@ class NetworkProtocol : public Node netipmidBasePath)) { crow::connections::systemBus->async_method_call( - [ipmiProtocolEnabled, - asyncResp](const boost::system::error_code ec) { - if (ec) + [asyncResp](const boost::system::error_code ec2) { + if (ec2) { messages::internalError(asyncResp->res); return; @@ -466,9 +465,8 @@ class NetworkProtocol : public Node "Running", std::variant<bool>{ipmiProtocolEnabled}); crow::connections::systemBus->async_method_call( - [ipmiProtocolEnabled, - asyncResp](const boost::system::error_code ec) { - if (ec) + [asyncResp](const boost::system::error_code ec2) { + if (ec2) { messages::internalError(asyncResp->res); return; diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp index 544c42b7cf..031657ae59 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -114,11 +114,11 @@ class Power : public Node } crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec) { - if (ec) + [asyncResp](const boost::system::error_code ec2) { + if (ec2) { BMCWEB_LOG_DEBUG - << "Power Limit Set: Dbus error: " << ec; + << "Power Limit Set: Dbus error: " << ec2; messages::internalError(asyncResp->res); return; } diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 99a03c9bf6..d1895c45fb 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -320,7 +320,7 @@ void getConnections( * allSensors list. Eliminate Thermal sensors when a Power request is * made, and eliminate Power sensors when a Thermal request is made. */ -void reduceSensorList( +inline void reduceSensorList( std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp, const std::vector<std::string>* allSensors, std::shared_ptr<boost::container::flat_set<std::string>> activeSensors) @@ -623,7 +623,7 @@ void getObjectManagerPaths(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp, * @param inventoryItem D-Bus inventory item associated with a sensor. * @return State value for inventory item. */ -static std::string getState(const InventoryItem* inventoryItem) +inline std::string getState(const InventoryItem* inventoryItem) { if ((inventoryItem != nullptr) && !(inventoryItem->isPresent)) { @@ -641,7 +641,7 @@ static std::string getState(const InventoryItem* inventoryItem) * be nullptr if no associated inventory item was found. * @return Health value for sensor. */ -static std::string getHealth( +inline std::string getHealth( nlohmann::json& sensorJson, const boost::container::flat_map< std::string, boost::container::flat_map<std::string, SensorVariant>>& @@ -759,7 +759,7 @@ static std::string getHealth( return "OK"; } -static void setLedState(nlohmann::json& sensorJson, +inline void setLedState(nlohmann::json& sensorJson, const InventoryItem* inventoryItem) { if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty()) @@ -775,7 +775,7 @@ static void setLedState(nlohmann::json& sensorJson, case LedState::BLINK: sensorJson["IndicatorLED"] = "Blinking"; break; - default: + case LedState::UNKNOWN: break; } } @@ -793,7 +793,7 @@ static void setLedState(nlohmann::json& sensorJson, * @param inventoryItem D-Bus inventory item associated with the sensor. Will * be nullptr if no associated inventory item was found. */ -void objectInterfacesToJson( +inline void objectInterfacesToJson( const std::string& sensorName, const std::string& sensorType, std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, const boost::container::flat_map< @@ -1043,7 +1043,7 @@ void objectInterfacesToJson( BMCWEB_LOG_DEBUG << "Added sensor " << sensorName; } -static void +inline void populateFanRedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp) { crow::connections::systemBus->async_method_call( @@ -1250,7 +1250,7 @@ static void "xyz.openbmc_project.Control.FanRedundancy"}); } -void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) +inline void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) { nlohmann::json& response = SensorsAsyncResp->res.jsonValue; std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"}; @@ -1295,7 +1295,7 @@ void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) * @param invItemObjPath D-Bus object path of inventory item. * @return Inventory item within vector, or nullptr if no match found. */ -static InventoryItem* findInventoryItem( +inline InventoryItem* findInventoryItem( std::shared_ptr<std::vector<InventoryItem>> inventoryItems, const std::string& invItemObjPath) { @@ -1315,7 +1315,7 @@ static InventoryItem* findInventoryItem( * @param sensorObjPath D-Bus object path of sensor. * @return Inventory item within vector, or nullptr if no match found. */ -static InventoryItem* findInventoryItemForSensor( +inline InventoryItem* findInventoryItemForSensor( std::shared_ptr<std::vector<InventoryItem>> inventoryItems, const std::string& sensorObjPath) { @@ -1363,7 +1363,7 @@ inline InventoryItem* * @param invItemObjPath D-Bus object path of inventory item. * @param sensorObjPath D-Bus object path of sensor */ -static void +inline void addInventoryItem(std::shared_ptr<std::vector<InventoryItem>> inventoryItems, const std::string& invItemObjPath, const std::string& sensorObjPath) @@ -1396,7 +1396,7 @@ static void * @param interfacesDict Map containing D-Bus interfaces and their properties * for the specified inventory item. */ -static void storeInventoryItemData( +inline void storeInventoryItemData( InventoryItem& inventoryItem, const boost::container::flat_map< std::string, boost::container::flat_map<std::string, SensorVariant>>& @@ -2348,7 +2348,7 @@ static void getInventoryItems( * @param chassisId Chassis that contains the power supply. * @return JSON PowerSupply object for the specified inventory item. */ -static nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, +inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, const InventoryItem& inventoryItem, const std::string& chassisId) { @@ -2416,7 +2416,7 @@ static nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, * implements ObjectManager. * @param inventoryItems Inventory items associated with the sensors. */ -void getSensorData( +inline void getSensorData( std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp, const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames, const boost::container::flat_set<std::string>& connections, @@ -2596,11 +2596,11 @@ void getSensorData( crow::connections::systemBus->async_method_call( getManagedObjectsCb, connection, objectMgrPath, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); - }; + } BMCWEB_LOG_DEBUG << "getSensorData exit"; } -void processSensorList( +inline void processSensorList( std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp, std::shared_ptr<boost::container::flat_set<std::string>> sensorNames) { @@ -2651,7 +2651,7 @@ void processSensorList( * chassis. * @param SensorsAsyncResp Pointer to object holding response data */ -void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) +inline void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) { BMCWEB_LOG_DEBUG << "getChassisData enter"; auto getChassisCb = @@ -2678,7 +2678,7 @@ void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) * @param sensorsModified The list of sensors that were found as a result of * repeated calls to this function */ -bool findSensorNameUsingSensorPath( +inline bool findSensorNameUsingSensorPath( std::string_view sensorName, boost::container::flat_set<std::string>& sensorsList, boost::container::flat_set<std::string>& sensorsModified) @@ -2707,7 +2707,7 @@ bool findSensorNameUsingSensorPath( * @param allCollections Collections extract from sensors' request patch info * @param chassisSubNode Chassis Node for which the query has to happen */ -void setSensorsOverride( +inline void setSensorsOverride( std::shared_ptr<SensorsAsyncResp> sensorAsyncResp, std::unordered_map<std::string, std::vector<nlohmann::json>>& allCollections) @@ -2832,7 +2832,7 @@ void setSensorsOverride( getChassis(sensorAsyncResp, std::move(getChassisSensorListCb)); } -bool isOverridingAllowed(const std::string& manufacturingModeStatus) +inline bool isOverridingAllowed(const std::string& manufacturingModeStatus) { if (manufacturingModeStatus == "xyz.openbmc_project.Control.Security.SpecialMode.Modes.Manufacturing") @@ -2860,7 +2860,7 @@ bool isOverridingAllowed(const std::string& manufacturingModeStatus) * @param allCollections Collections extract from sensors' request patch info * @param chassisSubNode Chassis Node for which the query has to happen */ -void checkAndDoSensorsOverride( +inline void checkAndDoSensorsOverride( std::shared_ptr<SensorsAsyncResp> sensorAsyncResp, std::unordered_map<std::string, std::vector<nlohmann::json>>& allCollections) @@ -2872,13 +2872,13 @@ void checkAndDoSensorsOverride( "xyz.openbmc_project.Security.SpecialMode"}; crow::connections::systemBus->async_method_call( - [sensorAsyncResp, allCollections](const boost::system::error_code ec, + [sensorAsyncResp, allCollections](const boost::system::error_code ec2, const GetSubTreeType& resp) mutable { - if (ec) + if (ec2) { BMCWEB_LOG_DEBUG << "Error in querying GetSubTree with Object Mapper. " - << ec; + << ec2; messages::internalError(sensorAsyncResp->res); return; } @@ -2972,8 +2972,9 @@ void checkAndDoSensorsOverride( * @param node Node (group) of sensors. See sensors::node for supported values * @param mapComplete Callback to be called with retrieval result */ -void retrieveUriToDbusMap(const std::string& chassis, const std::string& node, - SensorsAsyncResp::DataCompleteCb&& mapComplete) +inline void retrieveUriToDbusMap(const std::string& chassis, + const std::string& node, + SensorsAsyncResp::DataCompleteCb&& mapComplete) { auto typesIt = sensors::dbus::types.find(node); if (typesIt == sensors::dbus::types.end()) diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp index 0114c4e167..9b1e2d7e33 100644 --- a/redfish-core/lib/storage.hpp +++ b/redfish-core/lib/storage.hpp @@ -176,11 +176,11 @@ class Storage : public Node storageController["Status"]["State"] = "Enabled"; crow::connections::systemBus->async_method_call( - [asyncResp, index](const boost::system::error_code ec, + [asyncResp, index](const boost::system::error_code ec2, const std::variant<bool> present) { // this interface isn't necessary, only check it if // we get a good return - if (ec) + if (ec2) { return; } @@ -203,12 +203,12 @@ class Storage : public Node crow::connections::systemBus->async_method_call( [asyncResp, - index](const boost::system::error_code ec, + index](const boost::system::error_code ec2, const std::vector<std::pair< std::string, std::variant<bool, std::string, uint64_t>>>& propertiesList) { - if (ec) + if (ec2) { // this interface isn't necessary return; @@ -311,23 +311,23 @@ class Drive : public Node return; } - auto object = std::find_if( + auto object2 = std::find_if( subtree.begin(), subtree.end(), [&driveId](auto& object) { const std::string& path = object.first; return boost::ends_with(path, "/" + driveId); }); - if (object == subtree.end()) + if (object2 == subtree.end()) { messages::resourceNotFound(asyncResp->res, "Drive", driveId); return; } - const std::string& path = object->first; + const std::string& path = object2->first; const std::vector< std::pair<std::string, std::vector<std::string>>>& - connectionNames = object->second; + connectionNames = object2->second; asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; asyncResp->res.jsonValue["@odata.id"] = diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 9ca95d5405..c4bc3d4863 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -38,8 +38,8 @@ namespace redfish * * @return None. */ -void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, - const std::variant<bool>& dimmState) +inline void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, + const std::variant<bool>& dimmState) { const bool* isDimmFunctional = std::get_if<bool>(&dimmState); if (isDimmFunctional == nullptr) @@ -72,8 +72,8 @@ void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, - const std::variant<bool>& cpuPresenceState) +inline void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, + const std::variant<bool>& cpuPresenceState) { const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); @@ -107,8 +107,9 @@ void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, - const std::variant<bool>& cpuFunctionalState) +inline void + modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, + const std::variant<bool>& cpuFunctionalState) { const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); @@ -143,8 +144,8 @@ void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -void getComputerSystem(std::shared_ptr<AsyncResp> aResp, - std::shared_ptr<HealthPopulate> systemHealth) +inline void getComputerSystem(std::shared_ptr<AsyncResp> aResp, + std::shared_ptr<HealthPopulate> systemHealth) { BMCWEB_LOG_DEBUG << "Get available system components."; @@ -590,7 +591,7 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -void getHostState(std::shared_ptr<AsyncResp> aResp) +inline void getHostState(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get host information."; crow::connections::systemBus->async_method_call( @@ -645,7 +646,7 @@ void getHostState(std::shared_ptr<AsyncResp> aResp) * @return Returns as a string, the boot source in Redfish terms. If translation * cannot be done, returns an empty string. */ -static std::string dbusToRfBootSource(const std::string& dbusSource) +inline std::string dbusToRfBootSource(const std::string& dbusSource) { if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") { @@ -685,7 +686,7 @@ static std::string dbusToRfBootSource(const std::string& dbusSource) * @return Returns as a string, the boot mode in Redfish terms. If translation * cannot be done, returns an empty string. */ -static std::string dbusToRfBootMode(const std::string& dbusMode) +inline std::string dbusToRfBootMode(const std::string& dbusMode) { if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") { @@ -714,7 +715,7 @@ static std::string dbusToRfBootMode(const std::string& dbusMode) * * @return Integer error code. */ -static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, +inline int assignBootParameters(std::shared_ptr<AsyncResp> aResp, const std::string& rfSource, std::string& bootSource, std::string& bootMode) { @@ -774,7 +775,7 @@ static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -static void getBootMode(std::shared_ptr<AsyncResp> aResp, +inline void getBootMode(std::shared_ptr<AsyncResp> aResp, std::string bootDbusObj) { crow::connections::systemBus->async_method_call( @@ -838,7 +839,7 @@ static void getBootMode(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) +inline void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) { std::string bootDbusObj = oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" @@ -889,7 +890,7 @@ static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) * * @return None. */ -static void getBootProperties(std::shared_ptr<AsyncResp> aResp) +inline void getBootProperties(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get boot information."; @@ -930,7 +931,7 @@ static void getBootProperties(std::shared_ptr<AsyncResp> aResp) * * @return None. */ -void getLastResetTime(std::shared_ptr<AsyncResp> aResp) +inline void getLastResetTime(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; @@ -973,7 +974,7 @@ void getLastResetTime(std::shared_ptr<AsyncResp> aResp) * * @return None. */ -void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) +inline void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; @@ -1064,7 +1065,7 @@ void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) * * @return None. */ -void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) +inline void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get power restore policy"; @@ -1123,7 +1124,7 @@ void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) * * @return Integer error code. */ -static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, +inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled, std::optional<std::string> bootSource, std::optional<std::string> bootEnable) @@ -1244,7 +1245,7 @@ static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, * * @return Integer error code. */ -static void setBootSourceProperties(std::shared_ptr<AsyncResp> aResp, +inline void setBootSourceProperties(std::shared_ptr<AsyncResp> aResp, std::optional<std::string> bootSource, std::optional<std::string> bootEnable) { @@ -1288,7 +1289,7 @@ static void setBootSourceProperties(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -static void setAutomaticRetry(std::shared_ptr<AsyncResp> aResp, +inline void setAutomaticRetry(std::shared_ptr<AsyncResp> aResp, const std::string&& automaticRetryConfig) { BMCWEB_LOG_DEBUG << "Set Automatic Retry."; @@ -1337,7 +1338,7 @@ static void setAutomaticRetry(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, +inline void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, std::optional<std::string> policy) { BMCWEB_LOG_DEBUG << "Set power restore policy."; @@ -1384,7 +1385,7 @@ static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, * * @return None. */ -void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) +inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get OEM information."; crow::connections::systemBus->async_method_call( @@ -1453,7 +1454,7 @@ void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) * @return Returns as a string, the timeout action in Redfish terms. If * translation cannot be done, returns an empty string. */ -static std::string dbusToRfWatchdogAction(const std::string& dbusAction) +inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) { if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") { @@ -1486,7 +1487,7 @@ static std::string dbusToRfWatchdogAction(const std::string& dbusAction) *If translation cannot be done, returns an empty string. */ -static std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) +inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) { if (rfAction == "None") { @@ -1515,7 +1516,7 @@ static std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) * * @return None. */ -void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) +inline void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) { BMCWEB_LOG_DEBUG << "Get host watchodg"; crow::connections::systemBus->async_method_call( @@ -1586,7 +1587,7 @@ void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) * * @return None. */ -static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, +inline void setWDTProperties(std::shared_ptr<AsyncResp> aResp, const std::optional<bool> wdtEnable, const std::optional<std::string>& wdtTimeOutAction) { diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index 1b9077dec0..d6c479f069 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -93,9 +93,9 @@ struct TaskData : std::enable_shared_from_this<TaskData> TaskData(std::function<bool(boost::system::error_code, sdbusplus::message::message&, const std::shared_ptr<TaskData>&)>&& handler, - const std::string& match, size_t idx) : + const std::string& matchIn, size_t idx) : callback(std::move(handler)), - matchStr(match), index(idx), + matchStr(matchIn), index(idx), startTime(std::chrono::system_clock::to_time_t( std::chrono::system_clock::now())), status("OK"), state("Running"), messages(nlohmann::json::array()), @@ -118,8 +118,8 @@ struct TaskData : std::enable_shared_from_this<TaskData> std::function<bool(boost::system::error_code, sdbusplus::message::message&, const std::shared_ptr<TaskData>&)>&& handler, - const std::string& match, size_t idx) : - TaskData(std::move(handler), match, idx) + const std::string& match2, size_t idx) : + TaskData(std::move(handler), match2, idx) {} }; diff --git a/redfish-core/ut/privileges_test.cpp b/redfish-core/ut/privileges_test.cpp index d857290250..1613fbb8cf 100644 --- a/redfish-core/ut/privileges_test.cpp +++ b/redfish-core/ut/privileges_test.cpp @@ -13,9 +13,7 @@ TEST(PrivilegeTest, PrivilegeConstructor) Privileges privileges{"Login", "ConfigureManager"}; EXPECT_THAT(privileges.getActivePrivilegeNames(PrivilegeType::BASE), - ::testing::UnorderedElementsAre( - ::testing::Pointee(&"Login"[0]), - ::testing::Pointee(&"ConfigureManager"[0]))); + ::testing::UnorderedElementsAre("Login", "ConfigureManager")); } TEST(PrivilegeTest, PrivilegeCheckForNoPrivilegesRequired) @@ -119,9 +117,7 @@ TEST(PrivilegeTest, GetActivePrivilegeNames) EXPECT_THAT(privileges.getActivePrivilegeNames(PrivilegeType::BASE), ::testing::UnorderedElementsAre( - ::testing::Pointee(expectedPrivileges[0]), - ::testing::Pointee(expectedPrivileges[1]), - ::testing::Pointee(expectedPrivileges[2]), - ::testing::Pointee(expectedPrivileges[3]), - ::testing::Pointee(expectedPrivileges[4]))); + expectedPrivileges[0], expectedPrivileges[1], + expectedPrivileges[2], expectedPrivileges[3], + expectedPrivileges[4])); } diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index 2e043d77c7..b626f5b0a2 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -32,7 +32,7 @@ constexpr int defaultPort = 18080; -void setupSocket(crow::App& app) +inline void setupSocket(crow::App& app) { int listenFd = sd_listen_fds(0); if (1 == listenFd) @@ -107,7 +107,6 @@ int main(int argc, char** argv) crow::login_routes::requestRoutes(app); - BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')'; setupSocket(app); crow::connections::systemBus = |