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 "node.hpp" 1970304cb5SJason M. Bills #include "registries.hpp" 2070304cb5SJason M. Bills #include "registries/base_message_registry.hpp" 21fbe8378fSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2274eec26bSSunitha Harish #include "registries/resource_event_message_registry.hpp" 23e51c710eSJames Feist #include "registries/task_event_message_registry.hpp" 2470304cb5SJason M. Bills 2570304cb5SJason M. Bills namespace redfish 2670304cb5SJason M. Bills { 2770304cb5SJason M. Bills 2870304cb5SJason M. Bills class MessageRegistryFileCollection : public Node 2970304cb5SJason M. Bills { 3070304cb5SJason M. Bills public: 3152cc112dSEd Tanous MessageRegistryFileCollection(App& app) : 3270304cb5SJason M. Bills Node(app, "/redfish/v1/Registries/") 3370304cb5SJason M. Bills { 3470304cb5SJason M. Bills entityPrivileges = { 3570304cb5SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 3670304cb5SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 3770304cb5SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3870304cb5SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3970304cb5SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 4070304cb5SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 4170304cb5SJason M. Bills } 4270304cb5SJason M. Bills 4370304cb5SJason M. Bills private: 4470304cb5SJason M. Bills /** 4570304cb5SJason M. Bills * Functions triggers appropriate requests on DBus 4670304cb5SJason M. Bills */ 47*8d1b46d7Szhanghch05 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 48*8d1b46d7Szhanghch05 const crow::Request&, const std::vector<std::string>&) override 4970304cb5SJason M. Bills { 5070304cb5SJason M. Bills // Collections don't include the static data added by SubRoute because 5170304cb5SJason M. Bills // it has a duplicate entry for members 5214c8aee2SEd Tanous 53*8d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 5414c8aee2SEd Tanous {"@odata.type", 5514c8aee2SEd Tanous "#MessageRegistryFileCollection.MessageRegistryFileCollection"}, 5614c8aee2SEd Tanous {"@odata.id", "/redfish/v1/Registries"}, 5714c8aee2SEd Tanous {"Name", "MessageRegistryFile Collection"}, 5814c8aee2SEd Tanous {"Description", "Collection of MessageRegistryFiles"}, 5974eec26bSSunitha Harish {"Members@odata.count", 4}, 6014c8aee2SEd Tanous {"Members", 6114c8aee2SEd Tanous {{{"@odata.id", "/redfish/v1/Registries/Base"}}, 62e51c710eSJames Feist {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}}, 6374eec26bSSunitha Harish {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}}, 6414c8aee2SEd Tanous {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}}; 6570304cb5SJason M. Bills } 6670304cb5SJason M. Bills }; 6770304cb5SJason M. Bills 68e51c710eSJames Feist class MessageRegistryFile : public Node 6970304cb5SJason M. Bills { 7070304cb5SJason M. Bills public: 7152cc112dSEd Tanous MessageRegistryFile(App& app) : 72e51c710eSJames Feist Node(app, "/redfish/v1/Registries/<str>/", std::string()) 7370304cb5SJason M. Bills { 7470304cb5SJason M. Bills entityPrivileges = { 7570304cb5SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 7670304cb5SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 7770304cb5SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 7870304cb5SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 7970304cb5SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 8070304cb5SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 8170304cb5SJason M. Bills } 8270304cb5SJason M. Bills 8370304cb5SJason M. Bills private: 84*8d1b46d7Szhanghch05 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 85*8d1b46d7Szhanghch05 const crow::Request&, 8670304cb5SJason M. Bills const std::vector<std::string>& params) override 8770304cb5SJason M. Bills { 88e51c710eSJames Feist if (params.size() != 1) 89e51c710eSJames Feist { 90*8d1b46d7Szhanghch05 messages::internalError(asyncResp->res); 91e51c710eSJames Feist return; 92e51c710eSJames Feist } 93e51c710eSJames Feist 94e51c710eSJames Feist const std::string& registry = params[0]; 95e51c710eSJames Feist const message_registries::Header* header; 96e51c710eSJames Feist std::string dmtf = "DMTF "; 97e51c710eSJames Feist const char* url = nullptr; 98e51c710eSJames Feist 99e51c710eSJames Feist if (registry == "Base") 100e51c710eSJames Feist { 101e51c710eSJames Feist header = &message_registries::base::header; 102e51c710eSJames Feist url = message_registries::base::url; 103e51c710eSJames Feist } 104e51c710eSJames Feist else if (registry == "TaskEvent") 105e51c710eSJames Feist { 106e51c710eSJames Feist header = &message_registries::task_event::header; 107e51c710eSJames Feist url = message_registries::task_event::url; 108e51c710eSJames Feist } 109e51c710eSJames Feist else if (registry == "OpenBMC") 110e51c710eSJames Feist { 111e51c710eSJames Feist header = &message_registries::openbmc::header; 112e51c710eSJames Feist dmtf.clear(); 113e51c710eSJames Feist } 11474eec26bSSunitha Harish else if (registry == "ResourceEvent") 11574eec26bSSunitha Harish { 11674eec26bSSunitha Harish header = &message_registries::resource_event::header; 11774eec26bSSunitha Harish url = message_registries::resource_event::url; 11874eec26bSSunitha Harish } 119e51c710eSJames Feist else 120e51c710eSJames Feist { 121e51c710eSJames Feist messages::resourceNotFound( 122*8d1b46d7Szhanghch05 asyncResp->res, 123*8d1b46d7Szhanghch05 "#MessageRegistryFile.v1_1_0.MessageRegistryFile", registry); 124e51c710eSJames Feist return; 125e51c710eSJames Feist } 126e51c710eSJames Feist 127*8d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 128e51c710eSJames Feist {"@odata.id", "/redfish/v1/Registries/" + registry}, 12914c8aee2SEd Tanous {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"}, 130e51c710eSJames Feist {"Name", registry + " Message Registry File"}, 131e51c710eSJames Feist {"Description", 132e51c710eSJames Feist dmtf + registry + " Message Registry File Location"}, 133e51c710eSJames Feist {"Id", header->registryPrefix}, 134e51c710eSJames Feist {"Registry", header->id}, 13514c8aee2SEd Tanous {"Languages", {"en"}}, 13614c8aee2SEd Tanous {"Languages@odata.count", 1}, 13714c8aee2SEd Tanous {"Location", 13814c8aee2SEd Tanous {{{"Language", "en"}, 139e51c710eSJames Feist {"Uri", 140e51c710eSJames Feist "/redfish/v1/Registries/" + registry + "/" + registry}}}}, 14114c8aee2SEd Tanous {"Location@odata.count", 1}}; 142e51c710eSJames Feist 143e51c710eSJames Feist if (url != nullptr) 144e51c710eSJames Feist { 145*8d1b46d7Szhanghch05 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url; 146e51c710eSJames Feist } 14770304cb5SJason M. Bills } 14870304cb5SJason M. Bills }; 14970304cb5SJason M. Bills 150e51c710eSJames Feist class MessageRegistry : public Node 15170304cb5SJason M. Bills { 15270304cb5SJason M. Bills public: 15352cc112dSEd Tanous MessageRegistry(App& app) : 154e51c710eSJames Feist Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(), 155e51c710eSJames Feist std::string()) 15670304cb5SJason M. Bills { 15770304cb5SJason M. Bills entityPrivileges = { 15870304cb5SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 15970304cb5SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 16070304cb5SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 16170304cb5SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 16270304cb5SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 16370304cb5SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16470304cb5SJason M. Bills } 16570304cb5SJason M. Bills 16670304cb5SJason M. Bills private: 167*8d1b46d7Szhanghch05 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 168*8d1b46d7Szhanghch05 const crow::Request&, 16970304cb5SJason M. Bills const std::vector<std::string>& params) override 17070304cb5SJason M. Bills { 171e51c710eSJames Feist if (params.size() != 2) 172e51c710eSJames Feist { 173*8d1b46d7Szhanghch05 messages::internalError(asyncResp->res); 174e51c710eSJames Feist return; 175e51c710eSJames Feist } 176e51c710eSJames Feist 177e51c710eSJames Feist const std::string& registry = params[0]; 178e51c710eSJames Feist const std::string& registry1 = params[1]; 179e51c710eSJames Feist 180e51c710eSJames Feist const message_registries::Header* header; 181e51c710eSJames Feist std::vector<const message_registries::MessageEntry*> registryEntries; 182e51c710eSJames Feist if (registry == "Base") 183e51c710eSJames Feist { 184e51c710eSJames Feist header = &message_registries::base::header; 185e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 186e51c710eSJames Feist message_registries::base::registry) 187e51c710eSJames Feist { 188e51c710eSJames Feist registryEntries.emplace_back(&entry); 189e51c710eSJames Feist } 190e51c710eSJames Feist } 191e51c710eSJames Feist else if (registry == "TaskEvent") 192e51c710eSJames Feist { 193e51c710eSJames Feist header = &message_registries::task_event::header; 194e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 195e51c710eSJames Feist message_registries::task_event::registry) 196e51c710eSJames Feist { 197e51c710eSJames Feist registryEntries.emplace_back(&entry); 198e51c710eSJames Feist } 199e51c710eSJames Feist } 200e51c710eSJames Feist else if (registry == "OpenBMC") 201e51c710eSJames Feist { 202e51c710eSJames Feist header = &message_registries::openbmc::header; 203e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 204e51c710eSJames Feist message_registries::openbmc::registry) 205e51c710eSJames Feist { 206e51c710eSJames Feist registryEntries.emplace_back(&entry); 207e51c710eSJames Feist } 208e51c710eSJames Feist } 20974eec26bSSunitha Harish else if (registry == "ResourceEvent") 21074eec26bSSunitha Harish { 21174eec26bSSunitha Harish header = &message_registries::resource_event::header; 21274eec26bSSunitha Harish for (const message_registries::MessageEntry& entry : 21374eec26bSSunitha Harish message_registries::resource_event::registry) 21474eec26bSSunitha Harish { 21574eec26bSSunitha Harish registryEntries.emplace_back(&entry); 21674eec26bSSunitha Harish } 21774eec26bSSunitha Harish } 218e51c710eSJames Feist else 219e51c710eSJames Feist { 220e51c710eSJames Feist messages::resourceNotFound( 221*8d1b46d7Szhanghch05 asyncResp->res, 222*8d1b46d7Szhanghch05 "#MessageRegistryFile.v1_1_0.MessageRegistryFile", registry); 223e51c710eSJames Feist return; 224e51c710eSJames Feist } 225e51c710eSJames Feist 226e51c710eSJames Feist if (registry != registry1) 227e51c710eSJames Feist { 228*8d1b46d7Szhanghch05 messages::resourceNotFound(asyncResp->res, header->type, registry1); 229e51c710eSJames Feist return; 230e51c710eSJames Feist } 231e51c710eSJames Feist 232*8d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 233*8d1b46d7Szhanghch05 {"@Redfish.Copyright", header->copyright}, 234e51c710eSJames Feist {"@odata.type", header->type}, 235e51c710eSJames Feist {"Id", header->id}, 236e51c710eSJames Feist {"Name", header->name}, 237e51c710eSJames Feist {"Language", header->language}, 238e51c710eSJames Feist {"Description", header->description}, 239e51c710eSJames Feist {"RegistryPrefix", header->registryPrefix}, 240e51c710eSJames Feist {"RegistryVersion", header->registryVersion}, 241e51c710eSJames Feist {"OwningEntity", header->owningEntity}}; 24270304cb5SJason M. Bills 243*8d1b46d7Szhanghch05 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; 24470304cb5SJason M. Bills 24570304cb5SJason M. Bills // Go through the Message Registry and populate each Message 246e51c710eSJames Feist for (const message_registries::MessageEntry* message : registryEntries) 24770304cb5SJason M. Bills { 248e51c710eSJames Feist nlohmann::json& obj = messageObj[message->first]; 249e51c710eSJames Feist obj = {{"Description", message->second.description}, 250e51c710eSJames Feist {"Message", message->second.message}, 251e51c710eSJames Feist {"Severity", message->second.severity}, 252e7808c93SGunnar Mills {"MessageSeverity", message->second.messageSeverity}, 253e51c710eSJames Feist {"NumberOfArgs", message->second.numberOfArgs}, 254e51c710eSJames Feist {"Resolution", message->second.resolution}}; 255e51c710eSJames Feist if (message->second.numberOfArgs > 0) 25670304cb5SJason M. Bills { 25714c8aee2SEd Tanous nlohmann::json& messageParamArray = obj["ParamTypes"]; 258e51c710eSJames Feist for (const char* str : message->second.paramTypes) 25970304cb5SJason M. Bills { 26070304cb5SJason M. Bills if (str == nullptr) 26170304cb5SJason M. Bills { 26270304cb5SJason M. Bills break; 26370304cb5SJason M. Bills } 26470304cb5SJason M. Bills messageParamArray.push_back(str); 26570304cb5SJason M. Bills } 26670304cb5SJason M. Bills } 26770304cb5SJason M. Bills } 26870304cb5SJason M. Bills } 26970304cb5SJason M. Bills }; 27070304cb5SJason M. Bills 27170304cb5SJason M. Bills } // namespace redfish 272