170304cb5SJason M. Bills /* 270304cb5SJason M. Bills // Copyright (c) 2019 Intel Corporation 370304cb5SJason M. Bills // 470304cb5SJason M. Bills // Licensed under the Apache License, Version 2.0 (the "License"); 570304cb5SJason M. Bills // you may not use this file except in compliance with the License. 670304cb5SJason M. Bills // You may obtain a copy of the License at 770304cb5SJason M. Bills // 870304cb5SJason M. Bills // http://www.apache.org/licenses/LICENSE-2.0 970304cb5SJason M. Bills // 1070304cb5SJason M. Bills // Unless required by applicable law or agreed to in writing, software 1170304cb5SJason M. Bills // distributed under the License is distributed on an "AS IS" BASIS, 1270304cb5SJason M. Bills // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1370304cb5SJason M. Bills // See the License for the specific language governing permissions and 1470304cb5SJason M. Bills // limitations under the License. 1570304cb5SJason M. Bills */ 1670304cb5SJason M. Bills #pragma once 1770304cb5SJason M. Bills 1870304cb5SJason M. Bills #include "registries.hpp" 1970304cb5SJason M. Bills #include "registries/base_message_registry.hpp" 20fbe8378fSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2174eec26bSSunitha Harish #include "registries/resource_event_message_registry.hpp" 22e51c710eSJames Feist #include "registries/task_event_message_registry.hpp" 2370304cb5SJason M. Bills 247e860f15SJohn Edward Broadbent #include <app.hpp> 2545ca1b86SEd Tanous #include <query.hpp> 26ed398213SEd Tanous #include <registries/privilege_registry.hpp> 277e860f15SJohn Edward Broadbent 2870304cb5SJason M. Bills namespace redfish 2970304cb5SJason M. Bills { 3070304cb5SJason M. Bills 31dff07827SJohn Edward Broadbent inline void handleMessageRegistryFileCollectionGet( 3245ca1b86SEd Tanous crow::App& app, const crow::Request& req, 33104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3470304cb5SJason M. Bills { 353ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3645ca1b86SEd Tanous { 3745ca1b86SEd Tanous return; 3845ca1b86SEd Tanous } 397e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 407e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 4114c8aee2SEd Tanous 421476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 431476687dSEd Tanous "#MessageRegistryFileCollection.MessageRegistryFileCollection"; 441476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries"; 451476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection"; 461476687dSEd Tanous asyncResp->res.jsonValue["Description"] = 471476687dSEd Tanous "Collection of MessageRegistryFiles"; 481476687dSEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 4; 491476687dSEd Tanous asyncResp->res.jsonValue["Members"] = { 501476687dSEd Tanous {{"@odata.id", "/redfish/v1/Registries/Base"}}, 51e51c710eSJames Feist {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}}, 5274eec26bSSunitha Harish {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}}, 531476687dSEd Tanous {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}; 5470304cb5SJason M. Bills } 5570304cb5SJason M. Bills 56dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFileCollection(App& app) 5770304cb5SJason M. Bills { 58dff07827SJohn Edward Broadbent /** 59dff07827SJohn Edward Broadbent * Functions triggers appropriate requests on DBus 60dff07827SJohn Edward Broadbent */ 61dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/") 62dff07827SJohn Edward Broadbent .privileges(redfish::privileges::getMessageRegistryFileCollection) 6345ca1b86SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 6445ca1b86SEd Tanous handleMessageRegistryFileCollectionGet, std::ref(app))); 65dff07827SJohn Edward Broadbent } 66dff07827SJohn Edward Broadbent 67dff07827SJohn Edward Broadbent inline void handleMessageRoutesMessageRegistryFileGet( 6845ca1b86SEd Tanous crow::App& app, const crow::Request& req, 69104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 70dff07827SJohn Edward Broadbent const std::string& registry) 71dff07827SJohn Edward Broadbent { 723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 7345ca1b86SEd Tanous { 7445ca1b86SEd Tanous return; 7545ca1b86SEd Tanous } 76fffb8c1fSEd Tanous const registries::Header* header = nullptr; 77e51c710eSJames Feist std::string dmtf = "DMTF "; 78e51c710eSJames Feist const char* url = nullptr; 79e51c710eSJames Feist 80e51c710eSJames Feist if (registry == "Base") 81e51c710eSJames Feist { 82fffb8c1fSEd Tanous header = ®istries::base::header; 83fffb8c1fSEd Tanous url = registries::base::url; 84e51c710eSJames Feist } 85e51c710eSJames Feist else if (registry == "TaskEvent") 86e51c710eSJames Feist { 87fffb8c1fSEd Tanous header = ®istries::task_event::header; 88fffb8c1fSEd Tanous url = registries::task_event::url; 89e51c710eSJames Feist } 90e51c710eSJames Feist else if (registry == "OpenBMC") 91e51c710eSJames Feist { 92fffb8c1fSEd Tanous header = ®istries::openbmc::header; 93e51c710eSJames Feist dmtf.clear(); 94e51c710eSJames Feist } 9574eec26bSSunitha Harish else if (registry == "ResourceEvent") 9674eec26bSSunitha Harish { 97fffb8c1fSEd Tanous header = ®istries::resource_event::header; 98fffb8c1fSEd Tanous url = registries::resource_event::url; 9974eec26bSSunitha Harish } 100e51c710eSJames Feist else 101e51c710eSJames Feist { 102*d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 1037e860f15SJohn Edward Broadbent registry); 104e51c710eSJames Feist return; 105e51c710eSJames Feist } 106e51c710eSJames Feist 1071476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1081476687dSEd Tanous "/redfish/v1/Registries/" + registry; 1091476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 1101476687dSEd Tanous "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; 1111476687dSEd Tanous asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; 1121476687dSEd Tanous asyncResp->res.jsonValue["Description"] = 1131476687dSEd Tanous dmtf + registry + " Message Registry File Location"; 1141476687dSEd Tanous asyncResp->res.jsonValue["Id"] = header->registryPrefix; 1151476687dSEd Tanous asyncResp->res.jsonValue["Registry"] = header->id; 1161476687dSEd Tanous asyncResp->res.jsonValue["Languages"] = {"en"}; 1171476687dSEd Tanous asyncResp->res.jsonValue["Languages@odata.count"] = 1; 1181476687dSEd Tanous asyncResp->res.jsonValue["Location"] = { 1191476687dSEd Tanous {{"Language", "en"}, 1201476687dSEd Tanous {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}; 1211476687dSEd Tanous 1221476687dSEd Tanous asyncResp->res.jsonValue["Location@odata.count"] = 1; 123e51c710eSJames Feist 124e51c710eSJames Feist if (url != nullptr) 125e51c710eSJames Feist { 126dff07827SJohn Edward Broadbent asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url; 127e51c710eSJames Feist } 12870304cb5SJason M. Bills } 12970304cb5SJason M. Bills 130dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFile(App& app) 13170304cb5SJason M. Bills { 132dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") 133ed398213SEd Tanous .privileges(redfish::privileges::getMessageRegistryFile) 13445ca1b86SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 13545ca1b86SEd Tanous handleMessageRoutesMessageRegistryFileGet, std::ref(app))); 136dff07827SJohn Edward Broadbent } 137dff07827SJohn Edward Broadbent 138dff07827SJohn Edward Broadbent inline void handleMessageRegistryGet( 13945ca1b86SEd Tanous crow::App& app, const crow::Request& req, 140104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1416e8c18f0SJohn Edward Broadbent const std::string& registry, const std::string& registryMatch) 1427e860f15SJohn Edward Broadbent 143e51c710eSJames Feist { 1443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 14545ca1b86SEd Tanous { 14645ca1b86SEd Tanous return; 14745ca1b86SEd Tanous } 148fffb8c1fSEd Tanous const registries::Header* header = nullptr; 149fffb8c1fSEd Tanous std::vector<const registries::MessageEntry*> registryEntries; 150e51c710eSJames Feist if (registry == "Base") 151e51c710eSJames Feist { 152fffb8c1fSEd Tanous header = ®istries::base::header; 153fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : registries::base::registry) 154e51c710eSJames Feist { 155e51c710eSJames Feist registryEntries.emplace_back(&entry); 156e51c710eSJames Feist } 157e51c710eSJames Feist } 158e51c710eSJames Feist else if (registry == "TaskEvent") 159e51c710eSJames Feist { 160fffb8c1fSEd Tanous header = ®istries::task_event::header; 161fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 162fffb8c1fSEd Tanous registries::task_event::registry) 163e51c710eSJames Feist { 164e51c710eSJames Feist registryEntries.emplace_back(&entry); 165e51c710eSJames Feist } 166e51c710eSJames Feist } 167e51c710eSJames Feist else if (registry == "OpenBMC") 168e51c710eSJames Feist { 169fffb8c1fSEd Tanous header = ®istries::openbmc::header; 170fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 171fffb8c1fSEd Tanous registries::openbmc::registry) 172e51c710eSJames Feist { 173e51c710eSJames Feist registryEntries.emplace_back(&entry); 174e51c710eSJames Feist } 175e51c710eSJames Feist } 17674eec26bSSunitha Harish else if (registry == "ResourceEvent") 17774eec26bSSunitha Harish { 178fffb8c1fSEd Tanous header = ®istries::resource_event::header; 179fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 180fffb8c1fSEd Tanous registries::resource_event::registry) 18174eec26bSSunitha Harish { 18274eec26bSSunitha Harish registryEntries.emplace_back(&entry); 18374eec26bSSunitha Harish } 18474eec26bSSunitha Harish } 185e51c710eSJames Feist else 186e51c710eSJames Feist { 187*d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 1887e860f15SJohn Edward Broadbent registry); 189e51c710eSJames Feist return; 190e51c710eSJames Feist } 191e51c710eSJames Feist 1926e8c18f0SJohn Edward Broadbent if (registry != registryMatch) 193e51c710eSJames Feist { 1946e8c18f0SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, header->type, registryMatch); 195e51c710eSJames Feist return; 196e51c710eSJames Feist } 197e51c710eSJames Feist 1981476687dSEd Tanous asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright; 1991476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = header->type; 2001476687dSEd Tanous asyncResp->res.jsonValue["Id"] = header->id; 2011476687dSEd Tanous asyncResp->res.jsonValue["Name"] = header->name; 2021476687dSEd Tanous asyncResp->res.jsonValue["Language"] = header->language; 2031476687dSEd Tanous asyncResp->res.jsonValue["Description"] = header->description; 2041476687dSEd Tanous asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix; 2051476687dSEd Tanous asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion; 2061476687dSEd Tanous asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity; 20770304cb5SJason M. Bills 208dff07827SJohn Edward Broadbent nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; 20970304cb5SJason M. Bills 21070304cb5SJason M. Bills // Go through the Message Registry and populate each Message 211fffb8c1fSEd Tanous for (const registries::MessageEntry* message : registryEntries) 21270304cb5SJason M. Bills { 213e51c710eSJames Feist nlohmann::json& obj = messageObj[message->first]; 2141476687dSEd Tanous obj["Description"] = message->second.description; 2151476687dSEd Tanous obj["Message"] = message->second.message; 2161476687dSEd Tanous obj["Severity"] = message->second.messageSeverity; 2171476687dSEd Tanous obj["MessageSeverity"] = message->second.messageSeverity; 2181476687dSEd Tanous obj["NumberOfArgs"] = message->second.numberOfArgs; 2191476687dSEd Tanous obj["Resolution"] = message->second.resolution; 220e51c710eSJames Feist if (message->second.numberOfArgs > 0) 22170304cb5SJason M. Bills { 22214c8aee2SEd Tanous nlohmann::json& messageParamArray = obj["ParamTypes"]; 223938f2568SEd Tanous messageParamArray = nlohmann::json::array(); 224e51c710eSJames Feist for (const char* str : message->second.paramTypes) 22570304cb5SJason M. Bills { 22670304cb5SJason M. Bills if (str == nullptr) 22770304cb5SJason M. Bills { 22870304cb5SJason M. Bills break; 22970304cb5SJason M. Bills } 23070304cb5SJason M. Bills messageParamArray.push_back(str); 23170304cb5SJason M. Bills } 23270304cb5SJason M. Bills } 23370304cb5SJason M. Bills } 23470304cb5SJason M. Bills } 23570304cb5SJason M. Bills 236dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistry(App& app) 237dff07827SJohn Edward Broadbent { 238dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") 239dff07827SJohn Edward Broadbent .privileges(redfish::privileges::getMessageRegistryFile) 24045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 24145ca1b86SEd Tanous std::bind_front(handleMessageRegistryGet, std::ref(app))); 242dff07827SJohn Edward Broadbent } 24370304cb5SJason M. Bills } // namespace redfish 244