xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 1476687deb1697d865b20458a0097c9ab5fd44e2)
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 {
3545ca1b86SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
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 
42*1476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
43*1476687dSEd Tanous         "#MessageRegistryFileCollection.MessageRegistryFileCollection";
44*1476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
45*1476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
46*1476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
47*1476687dSEd Tanous         "Collection of MessageRegistryFiles";
48*1476687dSEd Tanous     asyncResp->res.jsonValue["Members@odata.count"] = 4;
49*1476687dSEd Tanous     asyncResp->res.jsonValue["Members"] = {
50*1476687dSEd Tanous         {{"@odata.id", "/redfish/v1/Registries/Base"}},
51e51c710eSJames Feist         {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
5274eec26bSSunitha Harish         {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
53*1476687dSEd 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 {
7245ca1b86SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
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 = &registries::base::header;
83fffb8c1fSEd Tanous         url = registries::base::url;
84e51c710eSJames Feist     }
85e51c710eSJames Feist     else if (registry == "TaskEvent")
86e51c710eSJames Feist     {
87fffb8c1fSEd Tanous         header = &registries::task_event::header;
88fffb8c1fSEd Tanous         url = registries::task_event::url;
89e51c710eSJames Feist     }
90e51c710eSJames Feist     else if (registry == "OpenBMC")
91e51c710eSJames Feist     {
92fffb8c1fSEd Tanous         header = &registries::openbmc::header;
93e51c710eSJames Feist         dmtf.clear();
94e51c710eSJames Feist     }
9574eec26bSSunitha Harish     else if (registry == "ResourceEvent")
9674eec26bSSunitha Harish     {
97fffb8c1fSEd Tanous         header = &registries::resource_event::header;
98fffb8c1fSEd Tanous         url = registries::resource_event::url;
9974eec26bSSunitha Harish     }
100e51c710eSJames Feist     else
101e51c710eSJames Feist     {
102e51c710eSJames Feist         messages::resourceNotFound(
103dff07827SJohn Edward Broadbent             asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
1047e860f15SJohn Edward Broadbent             registry);
105e51c710eSJames Feist         return;
106e51c710eSJames Feist     }
107e51c710eSJames Feist 
108*1476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
109*1476687dSEd Tanous         "/redfish/v1/Registries/" + registry;
110*1476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
111*1476687dSEd Tanous         "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
112*1476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
113*1476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
114*1476687dSEd Tanous         dmtf + registry + " Message Registry File Location";
115*1476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = header->registryPrefix;
116*1476687dSEd Tanous     asyncResp->res.jsonValue["Registry"] = header->id;
117*1476687dSEd Tanous     asyncResp->res.jsonValue["Languages"] = {"en"};
118*1476687dSEd Tanous     asyncResp->res.jsonValue["Languages@odata.count"] = 1;
119*1476687dSEd Tanous     asyncResp->res.jsonValue["Location"] = {
120*1476687dSEd Tanous         {{"Language", "en"},
121*1476687dSEd Tanous          {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}};
122*1476687dSEd Tanous 
123*1476687dSEd Tanous     asyncResp->res.jsonValue["Location@odata.count"] = 1;
124e51c710eSJames Feist 
125e51c710eSJames Feist     if (url != nullptr)
126e51c710eSJames Feist     {
127dff07827SJohn Edward Broadbent         asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
128e51c710eSJames Feist     }
12970304cb5SJason M. Bills }
13070304cb5SJason M. Bills 
131dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFile(App& app)
13270304cb5SJason M. Bills {
133dff07827SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
134ed398213SEd Tanous         .privileges(redfish::privileges::getMessageRegistryFile)
13545ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
13645ca1b86SEd Tanous             handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
137dff07827SJohn Edward Broadbent }
138dff07827SJohn Edward Broadbent 
139dff07827SJohn Edward Broadbent inline void handleMessageRegistryGet(
14045ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
141104f09c9SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1426e8c18f0SJohn Edward Broadbent     const std::string& registry, const std::string& registryMatch)
1437e860f15SJohn Edward Broadbent 
144e51c710eSJames Feist {
14545ca1b86SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
14645ca1b86SEd Tanous     {
14745ca1b86SEd Tanous         return;
14845ca1b86SEd Tanous     }
149fffb8c1fSEd Tanous     const registries::Header* header = nullptr;
150fffb8c1fSEd Tanous     std::vector<const registries::MessageEntry*> registryEntries;
151e51c710eSJames Feist     if (registry == "Base")
152e51c710eSJames Feist     {
153fffb8c1fSEd Tanous         header = &registries::base::header;
154fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry : registries::base::registry)
155e51c710eSJames Feist         {
156e51c710eSJames Feist             registryEntries.emplace_back(&entry);
157e51c710eSJames Feist         }
158e51c710eSJames Feist     }
159e51c710eSJames Feist     else if (registry == "TaskEvent")
160e51c710eSJames Feist     {
161fffb8c1fSEd Tanous         header = &registries::task_event::header;
162fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
163fffb8c1fSEd Tanous              registries::task_event::registry)
164e51c710eSJames Feist         {
165e51c710eSJames Feist             registryEntries.emplace_back(&entry);
166e51c710eSJames Feist         }
167e51c710eSJames Feist     }
168e51c710eSJames Feist     else if (registry == "OpenBMC")
169e51c710eSJames Feist     {
170fffb8c1fSEd Tanous         header = &registries::openbmc::header;
171fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
172fffb8c1fSEd Tanous              registries::openbmc::registry)
173e51c710eSJames Feist         {
174e51c710eSJames Feist             registryEntries.emplace_back(&entry);
175e51c710eSJames Feist         }
176e51c710eSJames Feist     }
17774eec26bSSunitha Harish     else if (registry == "ResourceEvent")
17874eec26bSSunitha Harish     {
179fffb8c1fSEd Tanous         header = &registries::resource_event::header;
180fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
181fffb8c1fSEd Tanous              registries::resource_event::registry)
18274eec26bSSunitha Harish         {
18374eec26bSSunitha Harish             registryEntries.emplace_back(&entry);
18474eec26bSSunitha Harish         }
18574eec26bSSunitha Harish     }
186e51c710eSJames Feist     else
187e51c710eSJames Feist     {
188e51c710eSJames Feist         messages::resourceNotFound(
189dff07827SJohn Edward Broadbent             asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
1907e860f15SJohn Edward Broadbent             registry);
191e51c710eSJames Feist         return;
192e51c710eSJames Feist     }
193e51c710eSJames Feist 
1946e8c18f0SJohn Edward Broadbent     if (registry != registryMatch)
195e51c710eSJames Feist     {
1966e8c18f0SJohn Edward Broadbent         messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
197e51c710eSJames Feist         return;
198e51c710eSJames Feist     }
199e51c710eSJames Feist 
200*1476687dSEd Tanous     asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
201*1476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] = header->type;
202*1476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = header->id;
203*1476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = header->name;
204*1476687dSEd Tanous     asyncResp->res.jsonValue["Language"] = header->language;
205*1476687dSEd Tanous     asyncResp->res.jsonValue["Description"] = header->description;
206*1476687dSEd Tanous     asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
207*1476687dSEd Tanous     asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
208*1476687dSEd Tanous     asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
20970304cb5SJason M. Bills 
210dff07827SJohn Edward Broadbent     nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
21170304cb5SJason M. Bills 
21270304cb5SJason M. Bills     // Go through the Message Registry and populate each Message
213fffb8c1fSEd Tanous     for (const registries::MessageEntry* message : registryEntries)
21470304cb5SJason M. Bills     {
215e51c710eSJames Feist         nlohmann::json& obj = messageObj[message->first];
216*1476687dSEd Tanous         obj["Description"] = message->second.description;
217*1476687dSEd Tanous         obj["Message"] = message->second.message;
218*1476687dSEd Tanous         obj["Severity"] = message->second.messageSeverity;
219*1476687dSEd Tanous         obj["MessageSeverity"] = message->second.messageSeverity;
220*1476687dSEd Tanous         obj["NumberOfArgs"] = message->second.numberOfArgs;
221*1476687dSEd Tanous         obj["Resolution"] = message->second.resolution;
222e51c710eSJames Feist         if (message->second.numberOfArgs > 0)
22370304cb5SJason M. Bills         {
22414c8aee2SEd Tanous             nlohmann::json& messageParamArray = obj["ParamTypes"];
225938f2568SEd Tanous             messageParamArray = nlohmann::json::array();
226e51c710eSJames Feist             for (const char* str : message->second.paramTypes)
22770304cb5SJason M. Bills             {
22870304cb5SJason M. Bills                 if (str == nullptr)
22970304cb5SJason M. Bills                 {
23070304cb5SJason M. Bills                     break;
23170304cb5SJason M. Bills                 }
23270304cb5SJason M. Bills                 messageParamArray.push_back(str);
23370304cb5SJason M. Bills             }
23470304cb5SJason M. Bills         }
23570304cb5SJason M. Bills     }
23670304cb5SJason M. Bills }
23770304cb5SJason M. Bills 
238dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistry(App& app)
239dff07827SJohn Edward Broadbent {
240dff07827SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
241dff07827SJohn Edward Broadbent         .privileges(redfish::privileges::getMessageRegistryFile)
24245ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
24345ca1b86SEd Tanous             std::bind_front(handleMessageRegistryGet, std::ref(app)));
244dff07827SJohn Edward Broadbent }
24570304cb5SJason M. Bills } // namespace redfish
246