blob: 9d6f109360b7f1124246811823170fad5d2c6979 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Jason M. Bills70304cb2019-03-27 12:03:59 -070018#include "registries.hpp"
19#include "registries/base_message_registry.hpp"
Jason M. Billsfbe83782019-03-27 14:14:53 -070020#include "registries/openbmc_message_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050021#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070022#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070023
John Edward Broadbent7e860f12021-04-08 15:57:16 -070024#include <app.hpp>
Ed Tanous45ca1b82022-03-25 13:07:27 -070025#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070026#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070027
Ed Tanous613dabe2022-07-09 11:17:36 -070028#include <array>
29
Jason M. Bills70304cb2019-03-27 12:03:59 -070030namespace redfish
31{
32
John Edward Broadbentdff07822021-07-13 11:20:47 -070033inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070034 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080035 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070036{
Carson Labrado3ba00072022-06-06 19:40:56 +000037 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070038 {
39 return;
40 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070041 // Collections don't include the static data added by SubRoute
42 // because it has a duplicate entry for members
43
Ed Tanous14766872022-03-15 10:44:42 -070044 asyncResp->res.jsonValue["@odata.type"] =
45 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
46 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
47 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
48 asyncResp->res.jsonValue["Description"] =
49 "Collection of MessageRegistryFiles";
50 asyncResp->res.jsonValue["Members@odata.count"] = 4;
Ed Tanous613dabe2022-07-09 11:17:36 -070051
52 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
53 for (const char* memberName :
54 std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"}))
55 {
56 nlohmann::json::object_t member;
57 member["@odata.id"] = crow::utility::urlFromPieces(
58 "redfish", "v1", "Registries", memberName);
59 members.emplace_back(std::move(member));
60 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070061}
62
John Edward Broadbent7e860f12021-04-08 15:57:16 -070063inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070064{
Jason M. Bills70304cb2019-03-27 12:03:59 -070065 /**
66 * Functions triggers appropriate requests on DBus
67 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070068 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070069 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070070 .methods(boost::beast::http::verb::get)(std::bind_front(
71 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070072}
Ed Tanous14c8aee2019-06-13 13:39:16 -070073
John Edward Broadbentdff07822021-07-13 11:20:47 -070074inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070075 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080076 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070077 const std::string& registry)
78{
Carson Labrado3ba00072022-06-06 19:40:56 +000079 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070080 {
81 return;
82 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080083 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070084 std::string dmtf = "DMTF ";
85 const char* url = nullptr;
86
87 if (registry == "Base")
88 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080089 header = &registries::base::header;
90 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070091 }
92 else if (registry == "TaskEvent")
93 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080094 header = &registries::task_event::header;
95 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070096 }
97 else if (registry == "OpenBMC")
98 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080099 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700100 dmtf.clear();
101 }
102 else if (registry == "ResourceEvent")
103 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800104 header = &registries::resource_event::header;
105 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700106 }
107 else
108 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800109 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
110 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700111 return;
112 }
113
Ed Tanous14766872022-03-15 10:44:42 -0700114 asyncResp->res.jsonValue["@odata.id"] =
115 "/redfish/v1/Registries/" + registry;
116 asyncResp->res.jsonValue["@odata.type"] =
117 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
118 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
119 asyncResp->res.jsonValue["Description"] =
120 dmtf + registry + " Message Registry File Location";
121 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
122 asyncResp->res.jsonValue["Registry"] = header->id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700123 nlohmann::json::array_t languages;
124 languages.push_back("en");
125 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
126 asyncResp->res.jsonValue["Languages"] = std::move(languages);
127 nlohmann::json::array_t locationMembers;
128 nlohmann::json::object_t location;
129 location["Language"] = "en";
130 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700131
132 if (url != nullptr)
133 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700134 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700135 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700136 locationMembers.emplace_back(std::move(location));
137 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
138 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700139}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700140
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700141inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700142{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700143 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700144 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700145 .methods(boost::beast::http::verb::get)(std::bind_front(
146 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700147}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700148
John Edward Broadbentdff07822021-07-13 11:20:47 -0700149inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700150 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800151 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700152 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700153
John Edward Broadbentdff07822021-07-13 11:20:47 -0700154{
Carson Labrado3ba00072022-06-06 19:40:56 +0000155 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700156 {
157 return;
158 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800159 const registries::Header* header = nullptr;
160 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700161 if (registry == "Base")
162 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800163 header = &registries::base::header;
164 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700165 {
166 registryEntries.emplace_back(&entry);
167 }
168 }
169 else if (registry == "TaskEvent")
170 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800171 header = &registries::task_event::header;
172 for (const registries::MessageEntry& entry :
173 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700174 {
175 registryEntries.emplace_back(&entry);
176 }
177 }
178 else if (registry == "OpenBMC")
179 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800180 header = &registries::openbmc::header;
181 for (const registries::MessageEntry& entry :
182 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700183 {
184 registryEntries.emplace_back(&entry);
185 }
186 }
187 else if (registry == "ResourceEvent")
188 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800189 header = &registries::resource_event::header;
190 for (const registries::MessageEntry& entry :
191 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700192 {
193 registryEntries.emplace_back(&entry);
194 }
195 }
196 else
197 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800198 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
199 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700200 return;
201 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700202
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700203 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700204 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700205 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700206 return;
207 }
208
Ed Tanous14766872022-03-15 10:44:42 -0700209 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
210 asyncResp->res.jsonValue["@odata.type"] = header->type;
211 asyncResp->res.jsonValue["Id"] = header->id;
212 asyncResp->res.jsonValue["Name"] = header->name;
213 asyncResp->res.jsonValue["Language"] = header->language;
214 asyncResp->res.jsonValue["Description"] = header->description;
215 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
216 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
217 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700218
219 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
220
221 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800222 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700223 {
224 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700225 obj["Description"] = message->second.description;
226 obj["Message"] = message->second.message;
227 obj["Severity"] = message->second.messageSeverity;
228 obj["MessageSeverity"] = message->second.messageSeverity;
229 obj["NumberOfArgs"] = message->second.numberOfArgs;
230 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700231 if (message->second.numberOfArgs > 0)
232 {
233 nlohmann::json& messageParamArray = obj["ParamTypes"];
234 messageParamArray = nlohmann::json::array();
235 for (const char* str : message->second.paramTypes)
236 {
237 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700238 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700239 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700240 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700241 messageParamArray.push_back(str);
242 }
243 }
244 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700245}
246
247inline void requestRoutesMessageRegistry(App& app)
248{
249 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700250 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700251 .methods(boost::beast::http::verb::get)(
252 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700253}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700254} // namespace redfish