170304cb5SJason M. Bills /* 26be832e2SEd Tanous Copyright (c) 2019 Intel Corporation 36be832e2SEd Tanous 46be832e2SEd Tanous Licensed under the Apache License, Version 2.0 (the "License"); 56be832e2SEd Tanous you may not use this file except in compliance with the License. 66be832e2SEd Tanous You may obtain a copy of the License at 76be832e2SEd Tanous 86be832e2SEd Tanous http://www.apache.org/licenses/LICENSE-2.0 96be832e2SEd Tanous 106be832e2SEd Tanous Unless required by applicable law or agreed to in writing, software 116be832e2SEd Tanous distributed under the License is distributed on an "AS IS" BASIS, 126be832e2SEd Tanous WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136be832e2SEd Tanous See the License for the specific language governing permissions and 146be832e2SEd Tanous limitations under the License. 1570304cb5SJason M. Bills */ 1670304cb5SJason M. Bills #pragma once 1770304cb5SJason M. Bills 183ccb3adbSEd Tanous #include "app.hpp" 193ccb3adbSEd Tanous #include "query.hpp" 2070304cb5SJason M. Bills #include "registries.hpp" 21*f7a26073SMyung Bae #include "registries_selector.hpp" 2270304cb5SJason M. Bills 23ef4c65b7SEd Tanous #include <boost/url/format.hpp> 24ef4c65b7SEd Tanous 25613dabeaSEd Tanous #include <array> 26613dabeaSEd Tanous 2770304cb5SJason M. Bills namespace redfish 2870304cb5SJason M. Bills { 2970304cb5SJason M. Bills 30dff07827SJohn Edward Broadbent inline void handleMessageRegistryFileCollectionGet( 3145ca1b86SEd Tanous crow::App& app, const crow::Request& req, 32104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3370304cb5SJason M. Bills { 343ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3545ca1b86SEd Tanous { 3645ca1b86SEd Tanous return; 3745ca1b86SEd Tanous } 387e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 397e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 4014c8aee2SEd Tanous 411476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 421476687dSEd Tanous "#MessageRegistryFileCollection.MessageRegistryFileCollection"; 431476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries"; 441476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection"; 451476687dSEd Tanous asyncResp->res.jsonValue["Description"] = 461476687dSEd Tanous "Collection of MessageRegistryFiles"; 47613dabeaSEd Tanous 48613dabeaSEd Tanous nlohmann::json& members = asyncResp->res.jsonValue["Members"]; 49fb546105SMyung Bae 50fb546105SMyung Bae static constexpr const auto registryFiles = std::to_array( 51fb546105SMyung Bae {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry", 52fb546105SMyung Bae "HeartbeatEvent"}); 53fb546105SMyung Bae 54fb546105SMyung Bae for (const char* memberName : registryFiles) 55613dabeaSEd Tanous { 56613dabeaSEd Tanous nlohmann::json::object_t member; 57bd79bce8SPatrick Williams member["@odata.id"] = 58bd79bce8SPatrick Williams boost::urls::format("/redfish/v1/Registries/{}", memberName); 59613dabeaSEd Tanous members.emplace_back(std::move(member)); 60613dabeaSEd Tanous } 61fb546105SMyung Bae asyncResp->res.jsonValue["Members@odata.count"] = members.size(); 6270304cb5SJason M. Bills } 6370304cb5SJason M. Bills 64dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFileCollection(App& app) 6570304cb5SJason M. Bills { 66dff07827SJohn Edward Broadbent /** 67dff07827SJohn Edward Broadbent * Functions triggers appropriate requests on DBus 68dff07827SJohn Edward Broadbent */ 69dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/") 70dff07827SJohn Edward Broadbent .privileges(redfish::privileges::getMessageRegistryFileCollection) 7145ca1b86SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 7245ca1b86SEd Tanous handleMessageRegistryFileCollectionGet, std::ref(app))); 73dff07827SJohn Edward Broadbent } 74dff07827SJohn Edward Broadbent 75dff07827SJohn Edward Broadbent inline void handleMessageRoutesMessageRegistryFileGet( 7645ca1b86SEd Tanous crow::App& app, const crow::Request& req, 77104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 78dff07827SJohn Edward Broadbent const std::string& registry) 79dff07827SJohn Edward Broadbent { 803ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 8145ca1b86SEd Tanous { 8245ca1b86SEd Tanous return; 8345ca1b86SEd Tanous } 84e51c710eSJames Feist std::string dmtf = "DMTF "; 85*f7a26073SMyung Bae std::optional<registries::HeaderAndUrl> headerAndUrl = 86*f7a26073SMyung Bae registries::getRegistryHeaderAndUrlFromPrefix(registry); 87e51c710eSJames Feist 88*f7a26073SMyung Bae if (!headerAndUrl) 89e51c710eSJames Feist { 90d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 917e860f15SJohn Edward Broadbent registry); 92e51c710eSJames Feist return; 93e51c710eSJames Feist } 94*f7a26073SMyung Bae if (registry == "OpenBMC") 95*f7a26073SMyung Bae { 96*f7a26073SMyung Bae dmtf.clear(); 97*f7a26073SMyung Bae } 98*f7a26073SMyung Bae const registries::Header& header = headerAndUrl->header; 99*f7a26073SMyung Bae const char* url = headerAndUrl->url; 100e51c710eSJames Feist 1011476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 102ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Registries/{}", registry); 1031476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 1041476687dSEd Tanous "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; 1051476687dSEd Tanous asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; 106bd79bce8SPatrick Williams asyncResp->res.jsonValue["Description"] = 107bd79bce8SPatrick Williams dmtf + registry + " Message Registry File Location"; 108*f7a26073SMyung Bae asyncResp->res.jsonValue["Id"] = header.registryPrefix; 109*f7a26073SMyung Bae asyncResp->res.jsonValue["Registry"] = header.id; 110613dabeaSEd Tanous nlohmann::json::array_t languages; 111*f7a26073SMyung Bae languages.emplace_back(header.language); 112613dabeaSEd Tanous asyncResp->res.jsonValue["Languages@odata.count"] = languages.size(); 113613dabeaSEd Tanous asyncResp->res.jsonValue["Languages"] = std::move(languages); 114613dabeaSEd Tanous nlohmann::json::array_t locationMembers; 115613dabeaSEd Tanous nlohmann::json::object_t location; 116*f7a26073SMyung Bae location["Language"] = header.language; 117613dabeaSEd Tanous location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry; 118e51c710eSJames Feist 119e51c710eSJames Feist if (url != nullptr) 120e51c710eSJames Feist { 121613dabeaSEd Tanous location["PublicationUri"] = url; 122e51c710eSJames Feist } 123613dabeaSEd Tanous locationMembers.emplace_back(std::move(location)); 124613dabeaSEd Tanous asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size(); 125613dabeaSEd Tanous asyncResp->res.jsonValue["Location"] = std::move(locationMembers); 12670304cb5SJason M. Bills } 12770304cb5SJason M. Bills 128dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFile(App& app) 12970304cb5SJason M. Bills { 130dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") 131ed398213SEd Tanous .privileges(redfish::privileges::getMessageRegistryFile) 13245ca1b86SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 13345ca1b86SEd Tanous handleMessageRoutesMessageRegistryFileGet, std::ref(app))); 134dff07827SJohn Edward Broadbent } 135dff07827SJohn Edward Broadbent 136dff07827SJohn Edward Broadbent inline void handleMessageRegistryGet( 13745ca1b86SEd Tanous crow::App& app, const crow::Request& req, 138104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1396e8c18f0SJohn Edward Broadbent const std::string& registry, const std::string& registryMatch) 1407e860f15SJohn Edward Broadbent 141e51c710eSJames Feist { 1423ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 14345ca1b86SEd Tanous { 14445ca1b86SEd Tanous return; 14545ca1b86SEd Tanous } 146*f7a26073SMyung Bae 147*f7a26073SMyung Bae std::optional<registries::HeaderAndUrl> headerAndUrl = 148*f7a26073SMyung Bae registries::getRegistryHeaderAndUrlFromPrefix(registry); 149*f7a26073SMyung Bae if (!headerAndUrl) 150e51c710eSJames Feist { 151d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 1527e860f15SJohn Edward Broadbent registry); 153e51c710eSJames Feist return; 154e51c710eSJames Feist } 155e51c710eSJames Feist 156*f7a26073SMyung Bae const registries::Header& header = headerAndUrl->header; 1576e8c18f0SJohn Edward Broadbent if (registry != registryMatch) 158e51c710eSJames Feist { 159*f7a26073SMyung Bae messages::resourceNotFound(asyncResp->res, header.type, registryMatch); 160e51c710eSJames Feist return; 161e51c710eSJames Feist } 162e51c710eSJames Feist 163*f7a26073SMyung Bae asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright; 164*f7a26073SMyung Bae asyncResp->res.jsonValue["@odata.type"] = header.type; 165*f7a26073SMyung Bae asyncResp->res.jsonValue["Id"] = header.id; 166*f7a26073SMyung Bae asyncResp->res.jsonValue["Name"] = header.name; 167*f7a26073SMyung Bae asyncResp->res.jsonValue["Language"] = header.language; 168*f7a26073SMyung Bae asyncResp->res.jsonValue["Description"] = header.description; 169*f7a26073SMyung Bae asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix; 170*f7a26073SMyung Bae asyncResp->res.jsonValue["RegistryVersion"] = header.registryVersion; 171*f7a26073SMyung Bae asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity; 17270304cb5SJason M. Bills 173dff07827SJohn Edward Broadbent nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; 17470304cb5SJason M. Bills 17570304cb5SJason M. Bills // Go through the Message Registry and populate each Message 176*f7a26073SMyung Bae const std::span<const registries::MessageEntry> registryEntries = 177*f7a26073SMyung Bae registries::getRegistryFromPrefix(registry); 178*f7a26073SMyung Bae 179*f7a26073SMyung Bae for (const registries::MessageEntry& message : registryEntries) 18070304cb5SJason M. Bills { 181*f7a26073SMyung Bae nlohmann::json& obj = messageObj[message.first]; 182*f7a26073SMyung Bae obj["Description"] = message.second.description; 183*f7a26073SMyung Bae obj["Message"] = message.second.message; 184*f7a26073SMyung Bae obj["Severity"] = message.second.messageSeverity; 185*f7a26073SMyung Bae obj["MessageSeverity"] = message.second.messageSeverity; 186*f7a26073SMyung Bae obj["NumberOfArgs"] = message.second.numberOfArgs; 187*f7a26073SMyung Bae obj["Resolution"] = message.second.resolution; 188*f7a26073SMyung Bae if (message.second.numberOfArgs > 0) 18970304cb5SJason M. Bills { 19014c8aee2SEd Tanous nlohmann::json& messageParamArray = obj["ParamTypes"]; 191938f2568SEd Tanous messageParamArray = nlohmann::json::array(); 192*f7a26073SMyung Bae for (const char* str : message.second.paramTypes) 19370304cb5SJason M. Bills { 19470304cb5SJason M. Bills if (str == nullptr) 19570304cb5SJason M. Bills { 19670304cb5SJason M. Bills break; 19770304cb5SJason M. Bills } 19870304cb5SJason M. Bills messageParamArray.push_back(str); 19970304cb5SJason M. Bills } 20070304cb5SJason M. Bills } 20170304cb5SJason M. Bills } 20270304cb5SJason M. Bills } 20370304cb5SJason M. Bills 204dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistry(App& app) 205dff07827SJohn Edward Broadbent { 206dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") 207dff07827SJohn Edward Broadbent .privileges(redfish::privileges::getMessageRegistryFile) 20845ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 20945ca1b86SEd Tanous std::bind_front(handleMessageRegistryGet, std::ref(app))); 210dff07827SJohn Edward Broadbent } 21170304cb5SJason M. Bills } // namespace redfish 212