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 183ccb3adbSEd Tanous #include "app.hpp" 193ccb3adbSEd Tanous #include "query.hpp" 2070304cb5SJason M. Bills #include "registries.hpp" 2170304cb5SJason M. Bills #include "registries/base_message_registry.hpp" 22fbe8378fSJason M. Bills #include "registries/openbmc_message_registry.hpp" 233ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 2474eec26bSSunitha Harish #include "registries/resource_event_message_registry.hpp" 25e51c710eSJames Feist #include "registries/task_event_message_registry.hpp" 2670304cb5SJason M. Bills 27*ef4c65b7SEd Tanous #include <boost/url/format.hpp> 28*ef4c65b7SEd Tanous 29613dabeaSEd Tanous #include <array> 30613dabeaSEd Tanous 3170304cb5SJason M. Bills namespace redfish 3270304cb5SJason M. Bills { 3370304cb5SJason M. Bills 34dff07827SJohn Edward Broadbent inline void handleMessageRegistryFileCollectionGet( 3545ca1b86SEd Tanous crow::App& app, const crow::Request& req, 36104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3770304cb5SJason M. Bills { 383ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3945ca1b86SEd Tanous { 4045ca1b86SEd Tanous return; 4145ca1b86SEd Tanous } 427e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 437e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 4414c8aee2SEd Tanous 451476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 461476687dSEd Tanous "#MessageRegistryFileCollection.MessageRegistryFileCollection"; 471476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries"; 481476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection"; 491476687dSEd Tanous asyncResp->res.jsonValue["Description"] = 501476687dSEd Tanous "Collection of MessageRegistryFiles"; 511476687dSEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 4; 52613dabeaSEd Tanous 53613dabeaSEd Tanous nlohmann::json& members = asyncResp->res.jsonValue["Members"]; 54613dabeaSEd Tanous for (const char* memberName : 55613dabeaSEd Tanous std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"})) 56613dabeaSEd Tanous { 57613dabeaSEd Tanous nlohmann::json::object_t member; 58*ef4c65b7SEd Tanous member["@odata.id"] = boost::urls::format("/redfish/v1/Registries/{}", 59*ef4c65b7SEd Tanous memberName); 60613dabeaSEd Tanous members.emplace_back(std::move(member)); 61613dabeaSEd Tanous } 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 } 84fffb8c1fSEd Tanous const registries::Header* header = nullptr; 85e51c710eSJames Feist std::string dmtf = "DMTF "; 86e51c710eSJames Feist const char* url = nullptr; 87e51c710eSJames Feist 88e51c710eSJames Feist if (registry == "Base") 89e51c710eSJames Feist { 90fffb8c1fSEd Tanous header = ®istries::base::header; 91fffb8c1fSEd Tanous url = registries::base::url; 92e51c710eSJames Feist } 93e51c710eSJames Feist else if (registry == "TaskEvent") 94e51c710eSJames Feist { 95fffb8c1fSEd Tanous header = ®istries::task_event::header; 96fffb8c1fSEd Tanous url = registries::task_event::url; 97e51c710eSJames Feist } 98e51c710eSJames Feist else if (registry == "OpenBMC") 99e51c710eSJames Feist { 100fffb8c1fSEd Tanous header = ®istries::openbmc::header; 101e51c710eSJames Feist dmtf.clear(); 102e51c710eSJames Feist } 10374eec26bSSunitha Harish else if (registry == "ResourceEvent") 10474eec26bSSunitha Harish { 105fffb8c1fSEd Tanous header = ®istries::resource_event::header; 106fffb8c1fSEd Tanous url = registries::resource_event::url; 10774eec26bSSunitha Harish } 108e51c710eSJames Feist else 109e51c710eSJames Feist { 110d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 1117e860f15SJohn Edward Broadbent registry); 112e51c710eSJames Feist return; 113e51c710eSJames Feist } 114e51c710eSJames Feist 1151476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 116*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Registries/{}", registry); 1171476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 1181476687dSEd Tanous "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; 1191476687dSEd Tanous asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; 12089492a15SPatrick Williams asyncResp->res.jsonValue["Description"] = dmtf + registry + 12189492a15SPatrick Williams " Message Registry File Location"; 1221476687dSEd Tanous asyncResp->res.jsonValue["Id"] = header->registryPrefix; 1231476687dSEd Tanous asyncResp->res.jsonValue["Registry"] = header->id; 124613dabeaSEd Tanous nlohmann::json::array_t languages; 125ad539545SPatrick Williams languages.emplace_back("en"); 126613dabeaSEd Tanous asyncResp->res.jsonValue["Languages@odata.count"] = languages.size(); 127613dabeaSEd Tanous asyncResp->res.jsonValue["Languages"] = std::move(languages); 128613dabeaSEd Tanous nlohmann::json::array_t locationMembers; 129613dabeaSEd Tanous nlohmann::json::object_t location; 130613dabeaSEd Tanous location["Language"] = "en"; 131613dabeaSEd Tanous location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry; 132e51c710eSJames Feist 133e51c710eSJames Feist if (url != nullptr) 134e51c710eSJames Feist { 135613dabeaSEd Tanous location["PublicationUri"] = url; 136e51c710eSJames Feist } 137613dabeaSEd Tanous locationMembers.emplace_back(std::move(location)); 138613dabeaSEd Tanous asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size(); 139613dabeaSEd Tanous asyncResp->res.jsonValue["Location"] = std::move(locationMembers); 14070304cb5SJason M. Bills } 14170304cb5SJason M. Bills 142dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFile(App& app) 14370304cb5SJason M. Bills { 144dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") 145ed398213SEd Tanous .privileges(redfish::privileges::getMessageRegistryFile) 14645ca1b86SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 14745ca1b86SEd Tanous handleMessageRoutesMessageRegistryFileGet, std::ref(app))); 148dff07827SJohn Edward Broadbent } 149dff07827SJohn Edward Broadbent 150dff07827SJohn Edward Broadbent inline void handleMessageRegistryGet( 15145ca1b86SEd Tanous crow::App& app, const crow::Request& req, 152104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1536e8c18f0SJohn Edward Broadbent const std::string& registry, const std::string& registryMatch) 1547e860f15SJohn Edward Broadbent 155e51c710eSJames Feist { 1563ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 15745ca1b86SEd Tanous { 15845ca1b86SEd Tanous return; 15945ca1b86SEd Tanous } 160fffb8c1fSEd Tanous const registries::Header* header = nullptr; 161fffb8c1fSEd Tanous std::vector<const registries::MessageEntry*> registryEntries; 162e51c710eSJames Feist if (registry == "Base") 163e51c710eSJames Feist { 164fffb8c1fSEd Tanous header = ®istries::base::header; 165fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : registries::base::registry) 166e51c710eSJames Feist { 167e51c710eSJames Feist registryEntries.emplace_back(&entry); 168e51c710eSJames Feist } 169e51c710eSJames Feist } 170e51c710eSJames Feist else if (registry == "TaskEvent") 171e51c710eSJames Feist { 172fffb8c1fSEd Tanous header = ®istries::task_event::header; 173fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 174fffb8c1fSEd Tanous registries::task_event::registry) 175e51c710eSJames Feist { 176e51c710eSJames Feist registryEntries.emplace_back(&entry); 177e51c710eSJames Feist } 178e51c710eSJames Feist } 179e51c710eSJames Feist else if (registry == "OpenBMC") 180e51c710eSJames Feist { 181fffb8c1fSEd Tanous header = ®istries::openbmc::header; 182fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 183fffb8c1fSEd Tanous registries::openbmc::registry) 184e51c710eSJames Feist { 185e51c710eSJames Feist registryEntries.emplace_back(&entry); 186e51c710eSJames Feist } 187e51c710eSJames Feist } 18874eec26bSSunitha Harish else if (registry == "ResourceEvent") 18974eec26bSSunitha Harish { 190fffb8c1fSEd Tanous header = ®istries::resource_event::header; 191fffb8c1fSEd Tanous for (const registries::MessageEntry& entry : 192fffb8c1fSEd Tanous registries::resource_event::registry) 19374eec26bSSunitha Harish { 19474eec26bSSunitha Harish registryEntries.emplace_back(&entry); 19574eec26bSSunitha Harish } 19674eec26bSSunitha Harish } 197e51c710eSJames Feist else 198e51c710eSJames Feist { 199d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", 2007e860f15SJohn Edward Broadbent registry); 201e51c710eSJames Feist return; 202e51c710eSJames Feist } 203e51c710eSJames Feist 2046e8c18f0SJohn Edward Broadbent if (registry != registryMatch) 205e51c710eSJames Feist { 2066e8c18f0SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, header->type, registryMatch); 207e51c710eSJames Feist return; 208e51c710eSJames Feist } 209e51c710eSJames Feist 2101476687dSEd Tanous asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright; 2111476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = header->type; 2121476687dSEd Tanous asyncResp->res.jsonValue["Id"] = header->id; 2131476687dSEd Tanous asyncResp->res.jsonValue["Name"] = header->name; 2141476687dSEd Tanous asyncResp->res.jsonValue["Language"] = header->language; 2151476687dSEd Tanous asyncResp->res.jsonValue["Description"] = header->description; 2161476687dSEd Tanous asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix; 2171476687dSEd Tanous asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion; 2181476687dSEd Tanous asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity; 21970304cb5SJason M. Bills 220dff07827SJohn Edward Broadbent nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; 22170304cb5SJason M. Bills 22270304cb5SJason M. Bills // Go through the Message Registry and populate each Message 223fffb8c1fSEd Tanous for (const registries::MessageEntry* message : registryEntries) 22470304cb5SJason M. Bills { 225e51c710eSJames Feist nlohmann::json& obj = messageObj[message->first]; 2261476687dSEd Tanous obj["Description"] = message->second.description; 2271476687dSEd Tanous obj["Message"] = message->second.message; 2281476687dSEd Tanous obj["Severity"] = message->second.messageSeverity; 2291476687dSEd Tanous obj["MessageSeverity"] = message->second.messageSeverity; 2301476687dSEd Tanous obj["NumberOfArgs"] = message->second.numberOfArgs; 2311476687dSEd Tanous obj["Resolution"] = message->second.resolution; 232e51c710eSJames Feist if (message->second.numberOfArgs > 0) 23370304cb5SJason M. Bills { 23414c8aee2SEd Tanous nlohmann::json& messageParamArray = obj["ParamTypes"]; 235938f2568SEd Tanous messageParamArray = nlohmann::json::array(); 236e51c710eSJames Feist for (const char* str : message->second.paramTypes) 23770304cb5SJason M. Bills { 23870304cb5SJason M. Bills if (str == nullptr) 23970304cb5SJason M. Bills { 24070304cb5SJason M. Bills break; 24170304cb5SJason M. Bills } 24270304cb5SJason M. Bills messageParamArray.push_back(str); 24370304cb5SJason M. Bills } 24470304cb5SJason M. Bills } 24570304cb5SJason M. Bills } 24670304cb5SJason M. Bills } 24770304cb5SJason M. Bills 248dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistry(App& app) 249dff07827SJohn Edward Broadbent { 250dff07827SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") 251dff07827SJohn Edward Broadbent .privileges(redfish::privileges::getMessageRegistryFile) 25245ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 25345ca1b86SEd Tanous std::bind_front(handleMessageRegistryGet, std::ref(app))); 254dff07827SJohn Edward Broadbent } 25570304cb5SJason M. Bills } // namespace redfish 256