blob: 41e7e930bf1e94ea49420c3039a22596d54fa035 [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
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
19#include "query.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070020#include "registries.hpp"
21#include "registries/base_message_registry.hpp"
Jason M. Billsfbe83782019-03-27 14:14:53 -070022#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "registries/privilege_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050024#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070025#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070026
Ed Tanous613dabe2022-07-09 11:17:36 -070027#include <array>
28
Jason M. Bills70304cb2019-03-27 12:03:59 -070029namespace redfish
30{
31
John Edward Broadbentdff07822021-07-13 11:20:47 -070032inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070033 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080034 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070035{
Carson Labrado3ba00072022-06-06 19:40:56 +000036 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070037 {
38 return;
39 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070040 // Collections don't include the static data added by SubRoute
41 // because it has a duplicate entry for members
42
Ed Tanous14766872022-03-15 10:44:42 -070043 asyncResp->res.jsonValue["@odata.type"] =
44 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
45 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
46 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
47 asyncResp->res.jsonValue["Description"] =
48 "Collection of MessageRegistryFiles";
49 asyncResp->res.jsonValue["Members@odata.count"] = 4;
Ed Tanous613dabe2022-07-09 11:17:36 -070050
51 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
52 for (const char* memberName :
53 std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"}))
54 {
55 nlohmann::json::object_t member;
56 member["@odata.id"] = crow::utility::urlFromPieces(
57 "redfish", "v1", "Registries", memberName);
58 members.emplace_back(std::move(member));
59 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070060}
61
John Edward Broadbent7e860f12021-04-08 15:57:16 -070062inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070063{
Jason M. Bills70304cb2019-03-27 12:03:59 -070064 /**
65 * Functions triggers appropriate requests on DBus
66 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070067 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070068 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070069 .methods(boost::beast::http::verb::get)(std::bind_front(
70 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070071}
Ed Tanous14c8aee2019-06-13 13:39:16 -070072
John Edward Broadbentdff07822021-07-13 11:20:47 -070073inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070074 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080075 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070076 const std::string& registry)
77{
Carson Labrado3ba00072022-06-06 19:40:56 +000078 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070079 {
80 return;
81 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080082 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070083 std::string dmtf = "DMTF ";
84 const char* url = nullptr;
85
86 if (registry == "Base")
87 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080088 header = &registries::base::header;
89 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070090 }
91 else if (registry == "TaskEvent")
92 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080093 header = &registries::task_event::header;
94 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070095 }
96 else if (registry == "OpenBMC")
97 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080098 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -070099 dmtf.clear();
100 }
101 else if (registry == "ResourceEvent")
102 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800103 header = &registries::resource_event::header;
104 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700105 }
106 else
107 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800108 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
109 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700110 return;
111 }
112
Ed Tanous14766872022-03-15 10:44:42 -0700113 asyncResp->res.jsonValue["@odata.id"] =
114 "/redfish/v1/Registries/" + registry;
115 asyncResp->res.jsonValue["@odata.type"] =
116 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
117 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
118 asyncResp->res.jsonValue["Description"] =
119 dmtf + registry + " Message Registry File Location";
120 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
121 asyncResp->res.jsonValue["Registry"] = header->id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700122 nlohmann::json::array_t languages;
123 languages.push_back("en");
124 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
125 asyncResp->res.jsonValue["Languages"] = std::move(languages);
126 nlohmann::json::array_t locationMembers;
127 nlohmann::json::object_t location;
128 location["Language"] = "en";
129 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700130
131 if (url != nullptr)
132 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700133 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700134 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700135 locationMembers.emplace_back(std::move(location));
136 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
137 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700138}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700139
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700140inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700141{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700142 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700143 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700144 .methods(boost::beast::http::verb::get)(std::bind_front(
145 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700146}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700147
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700149 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800150 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700151 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700152
John Edward Broadbentdff07822021-07-13 11:20:47 -0700153{
Carson Labrado3ba00072022-06-06 19:40:56 +0000154 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700155 {
156 return;
157 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800158 const registries::Header* header = nullptr;
159 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700160 if (registry == "Base")
161 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800162 header = &registries::base::header;
163 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700164 {
165 registryEntries.emplace_back(&entry);
166 }
167 }
168 else if (registry == "TaskEvent")
169 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800170 header = &registries::task_event::header;
171 for (const registries::MessageEntry& entry :
172 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700173 {
174 registryEntries.emplace_back(&entry);
175 }
176 }
177 else if (registry == "OpenBMC")
178 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800179 header = &registries::openbmc::header;
180 for (const registries::MessageEntry& entry :
181 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700182 {
183 registryEntries.emplace_back(&entry);
184 }
185 }
186 else if (registry == "ResourceEvent")
187 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800188 header = &registries::resource_event::header;
189 for (const registries::MessageEntry& entry :
190 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700191 {
192 registryEntries.emplace_back(&entry);
193 }
194 }
195 else
196 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800197 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
198 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700199 return;
200 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700201
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700202 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700203 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700204 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700205 return;
206 }
207
Ed Tanous14766872022-03-15 10:44:42 -0700208 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
209 asyncResp->res.jsonValue["@odata.type"] = header->type;
210 asyncResp->res.jsonValue["Id"] = header->id;
211 asyncResp->res.jsonValue["Name"] = header->name;
212 asyncResp->res.jsonValue["Language"] = header->language;
213 asyncResp->res.jsonValue["Description"] = header->description;
214 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
215 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
216 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700217
218 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
219
220 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800221 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700222 {
223 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700224 obj["Description"] = message->second.description;
225 obj["Message"] = message->second.message;
226 obj["Severity"] = message->second.messageSeverity;
227 obj["MessageSeverity"] = message->second.messageSeverity;
228 obj["NumberOfArgs"] = message->second.numberOfArgs;
229 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700230 if (message->second.numberOfArgs > 0)
231 {
232 nlohmann::json& messageParamArray = obj["ParamTypes"];
233 messageParamArray = nlohmann::json::array();
234 for (const char* str : message->second.paramTypes)
235 {
236 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700237 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700238 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700239 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700240 messageParamArray.push_back(str);
241 }
242 }
243 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700244}
245
246inline void requestRoutesMessageRegistry(App& app)
247{
248 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700249 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700250 .methods(boost::beast::http::verb::get)(
251 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700252}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700253} // namespace redfish