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: 31*52cc112dSEd 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 */ 4770304cb5SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 4870304cb5SJason M. Bills const std::vector<std::string>& params) 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 5314c8aee2SEd Tanous 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"}}}}}; 6514c8aee2SEd Tanous 6614c8aee2SEd Tanous res.end(); 6770304cb5SJason M. Bills } 6870304cb5SJason M. Bills }; 6970304cb5SJason M. Bills 70e51c710eSJames Feist class MessageRegistryFile : public Node 7170304cb5SJason M. Bills { 7270304cb5SJason M. Bills public: 73*52cc112dSEd Tanous MessageRegistryFile(App& app) : 74e51c710eSJames Feist Node(app, "/redfish/v1/Registries/<str>/", std::string()) 7570304cb5SJason M. Bills { 7670304cb5SJason M. Bills entityPrivileges = { 7770304cb5SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 7870304cb5SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 7970304cb5SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 8070304cb5SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 8170304cb5SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 8270304cb5SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 8370304cb5SJason M. Bills } 8470304cb5SJason M. Bills 8570304cb5SJason M. Bills private: 8670304cb5SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 8770304cb5SJason M. Bills const std::vector<std::string>& params) override 8870304cb5SJason M. Bills { 89e51c710eSJames Feist if (params.size() != 1) 90e51c710eSJames Feist { 91e51c710eSJames Feist messages::internalError(res); 92e51c710eSJames Feist res.end(); 93e51c710eSJames Feist return; 94e51c710eSJames Feist } 95e51c710eSJames Feist 96e51c710eSJames Feist const std::string& registry = params[0]; 97e51c710eSJames Feist const message_registries::Header* header; 98e51c710eSJames Feist std::string dmtf = "DMTF "; 99e51c710eSJames Feist const char* url = nullptr; 100e51c710eSJames Feist 101e51c710eSJames Feist if (registry == "Base") 102e51c710eSJames Feist { 103e51c710eSJames Feist header = &message_registries::base::header; 104e51c710eSJames Feist url = message_registries::base::url; 105e51c710eSJames Feist } 106e51c710eSJames Feist else if (registry == "TaskEvent") 107e51c710eSJames Feist { 108e51c710eSJames Feist header = &message_registries::task_event::header; 109e51c710eSJames Feist url = message_registries::task_event::url; 110e51c710eSJames Feist } 111e51c710eSJames Feist else if (registry == "OpenBMC") 112e51c710eSJames Feist { 113e51c710eSJames Feist header = &message_registries::openbmc::header; 114e51c710eSJames Feist dmtf.clear(); 115e51c710eSJames Feist } 11674eec26bSSunitha Harish else if (registry == "ResourceEvent") 11774eec26bSSunitha Harish { 11874eec26bSSunitha Harish header = &message_registries::resource_event::header; 11974eec26bSSunitha Harish url = message_registries::resource_event::url; 12074eec26bSSunitha Harish } 121e51c710eSJames Feist else 122e51c710eSJames Feist { 123e51c710eSJames Feist messages::resourceNotFound( 124e51c710eSJames Feist res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile", 125e51c710eSJames Feist registry); 126e51c710eSJames Feist res.end(); 127e51c710eSJames Feist return; 128e51c710eSJames Feist } 129e51c710eSJames Feist 13014c8aee2SEd Tanous res.jsonValue = { 131e51c710eSJames Feist {"@odata.id", "/redfish/v1/Registries/" + registry}, 13214c8aee2SEd Tanous {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"}, 133e51c710eSJames Feist {"Name", registry + " Message Registry File"}, 134e51c710eSJames Feist {"Description", 135e51c710eSJames Feist dmtf + registry + " Message Registry File Location"}, 136e51c710eSJames Feist {"Id", header->registryPrefix}, 137e51c710eSJames Feist {"Registry", header->id}, 13814c8aee2SEd Tanous {"Languages", {"en"}}, 13914c8aee2SEd Tanous {"Languages@odata.count", 1}, 14014c8aee2SEd Tanous {"Location", 14114c8aee2SEd Tanous {{{"Language", "en"}, 142e51c710eSJames Feist {"Uri", 143e51c710eSJames Feist "/redfish/v1/Registries/" + registry + "/" + registry}}}}, 14414c8aee2SEd Tanous {"Location@odata.count", 1}}; 145e51c710eSJames Feist 146e51c710eSJames Feist if (url != nullptr) 147e51c710eSJames Feist { 148e51c710eSJames Feist res.jsonValue["Location"][0]["PublicationUri"] = url; 149e51c710eSJames Feist } 150e51c710eSJames Feist 15114c8aee2SEd Tanous res.end(); 15270304cb5SJason M. Bills } 15370304cb5SJason M. Bills }; 15470304cb5SJason M. Bills 155e51c710eSJames Feist class MessageRegistry : public Node 15670304cb5SJason M. Bills { 15770304cb5SJason M. Bills public: 158*52cc112dSEd Tanous MessageRegistry(App& app) : 159e51c710eSJames Feist Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(), 160e51c710eSJames Feist std::string()) 16170304cb5SJason M. Bills { 16270304cb5SJason M. Bills entityPrivileges = { 16370304cb5SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 16470304cb5SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 16570304cb5SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 16670304cb5SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 16770304cb5SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 16870304cb5SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16970304cb5SJason M. Bills } 17070304cb5SJason M. Bills 17170304cb5SJason M. Bills private: 17270304cb5SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 17370304cb5SJason M. Bills const std::vector<std::string>& params) override 17470304cb5SJason M. Bills { 175e51c710eSJames Feist if (params.size() != 2) 176e51c710eSJames Feist { 177e51c710eSJames Feist messages::internalError(res); 178e51c710eSJames Feist res.end(); 179e51c710eSJames Feist return; 180e51c710eSJames Feist } 181e51c710eSJames Feist 182e51c710eSJames Feist const std::string& registry = params[0]; 183e51c710eSJames Feist const std::string& registry1 = params[1]; 184e51c710eSJames Feist 185e51c710eSJames Feist const message_registries::Header* header; 186e51c710eSJames Feist std::vector<const message_registries::MessageEntry*> registryEntries; 187e51c710eSJames Feist if (registry == "Base") 188e51c710eSJames Feist { 189e51c710eSJames Feist header = &message_registries::base::header; 190e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 191e51c710eSJames Feist message_registries::base::registry) 192e51c710eSJames Feist { 193e51c710eSJames Feist registryEntries.emplace_back(&entry); 194e51c710eSJames Feist } 195e51c710eSJames Feist } 196e51c710eSJames Feist else if (registry == "TaskEvent") 197e51c710eSJames Feist { 198e51c710eSJames Feist header = &message_registries::task_event::header; 199e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 200e51c710eSJames Feist message_registries::task_event::registry) 201e51c710eSJames Feist { 202e51c710eSJames Feist registryEntries.emplace_back(&entry); 203e51c710eSJames Feist } 204e51c710eSJames Feist } 205e51c710eSJames Feist else if (registry == "OpenBMC") 206e51c710eSJames Feist { 207e51c710eSJames Feist header = &message_registries::openbmc::header; 208e51c710eSJames Feist for (const message_registries::MessageEntry& entry : 209e51c710eSJames Feist message_registries::openbmc::registry) 210e51c710eSJames Feist { 211e51c710eSJames Feist registryEntries.emplace_back(&entry); 212e51c710eSJames Feist } 213e51c710eSJames Feist } 21474eec26bSSunitha Harish else if (registry == "ResourceEvent") 21574eec26bSSunitha Harish { 21674eec26bSSunitha Harish header = &message_registries::resource_event::header; 21774eec26bSSunitha Harish for (const message_registries::MessageEntry& entry : 21874eec26bSSunitha Harish message_registries::resource_event::registry) 21974eec26bSSunitha Harish { 22074eec26bSSunitha Harish registryEntries.emplace_back(&entry); 22174eec26bSSunitha Harish } 22274eec26bSSunitha Harish } 223e51c710eSJames Feist else 224e51c710eSJames Feist { 225e51c710eSJames Feist messages::resourceNotFound( 226e51c710eSJames Feist res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile", 227e51c710eSJames Feist registry); 228e51c710eSJames Feist res.end(); 229e51c710eSJames Feist return; 230e51c710eSJames Feist } 231e51c710eSJames Feist 232e51c710eSJames Feist if (registry != registry1) 233e51c710eSJames Feist { 234e51c710eSJames Feist messages::resourceNotFound(res, header->type, registry1); 235e51c710eSJames Feist res.end(); 236e51c710eSJames Feist return; 237e51c710eSJames Feist } 238e51c710eSJames Feist 239e51c710eSJames Feist res.jsonValue = {{"@Redfish.Copyright", header->copyright}, 240e51c710eSJames Feist {"@odata.type", header->type}, 241e51c710eSJames Feist {"Id", header->id}, 242e51c710eSJames Feist {"Name", header->name}, 243e51c710eSJames Feist {"Language", header->language}, 244e51c710eSJames Feist {"Description", header->description}, 245e51c710eSJames Feist {"RegistryPrefix", header->registryPrefix}, 246e51c710eSJames Feist {"RegistryVersion", header->registryVersion}, 247e51c710eSJames Feist {"OwningEntity", header->owningEntity}}; 24870304cb5SJason M. Bills 24914c8aee2SEd Tanous nlohmann::json& messageObj = res.jsonValue["Messages"]; 25070304cb5SJason M. Bills 25170304cb5SJason M. Bills // Go through the Message Registry and populate each Message 252e51c710eSJames Feist for (const message_registries::MessageEntry* message : registryEntries) 25370304cb5SJason M. Bills { 254e51c710eSJames Feist nlohmann::json& obj = messageObj[message->first]; 255e51c710eSJames Feist obj = {{"Description", message->second.description}, 256e51c710eSJames Feist {"Message", message->second.message}, 257e51c710eSJames Feist {"Severity", message->second.severity}, 258e7808c93SGunnar Mills {"MessageSeverity", message->second.messageSeverity}, 259e51c710eSJames Feist {"NumberOfArgs", message->second.numberOfArgs}, 260e51c710eSJames Feist {"Resolution", message->second.resolution}}; 261e51c710eSJames Feist if (message->second.numberOfArgs > 0) 26270304cb5SJason M. Bills { 26314c8aee2SEd Tanous nlohmann::json& messageParamArray = obj["ParamTypes"]; 264e51c710eSJames Feist for (const char* str : message->second.paramTypes) 26570304cb5SJason M. Bills { 26670304cb5SJason M. Bills if (str == nullptr) 26770304cb5SJason M. Bills { 26870304cb5SJason M. Bills break; 26970304cb5SJason M. Bills } 27070304cb5SJason M. Bills messageParamArray.push_back(str); 27170304cb5SJason M. Bills } 27270304cb5SJason M. Bills } 27370304cb5SJason M. Bills } 27414c8aee2SEd Tanous res.end(); 27570304cb5SJason M. Bills } 27670304cb5SJason M. Bills }; 27770304cb5SJason M. Bills 27870304cb5SJason M. Bills } // namespace redfish 279