blob: ead4e38a67c7e9004a86bd5b57a5f0730352a31a [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 Tanousef4c65b2023-04-24 15:28:50 -070027#include <boost/url/format.hpp>
28
Ed Tanous613dabe2022-07-09 11:17:36 -070029#include <array>
30
Jason M. Bills70304cb2019-03-27 12:03:59 -070031namespace redfish
32{
33
John Edward Broadbentdff07822021-07-13 11:20:47 -070034inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070035 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080036 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070037{
Carson Labrado3ba00072022-06-06 19:40:56 +000038 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070039 {
40 return;
41 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070042 // Collections don't include the static data added by SubRoute
43 // because it has a duplicate entry for members
44
Ed Tanous14766872022-03-15 10:44:42 -070045 asyncResp->res.jsonValue["@odata.type"] =
46 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
47 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
48 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
49 asyncResp->res.jsonValue["Description"] =
50 "Collection of MessageRegistryFiles";
51 asyncResp->res.jsonValue["Members@odata.count"] = 4;
Ed Tanous613dabe2022-07-09 11:17:36 -070052
53 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
54 for (const char* memberName :
55 std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"}))
56 {
57 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -070058 member["@odata.id"] = boost::urls::format("/redfish/v1/Registries/{}",
59 memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070060 members.emplace_back(std::move(member));
61 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070062}
63
John Edward Broadbent7e860f12021-04-08 15:57:16 -070064inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070065{
Jason M. Bills70304cb2019-03-27 12:03:59 -070066 /**
67 * Functions triggers appropriate requests on DBus
68 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070069 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070070 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070071 .methods(boost::beast::http::verb::get)(std::bind_front(
72 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070073}
Ed Tanous14c8aee2019-06-13 13:39:16 -070074
John Edward Broadbentdff07822021-07-13 11:20:47 -070075inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070076 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080077 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070078 const std::string& registry)
79{
Carson Labrado3ba00072022-06-06 19:40:56 +000080 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070081 {
82 return;
83 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080084 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070085 std::string dmtf = "DMTF ";
86 const char* url = nullptr;
87
88 if (registry == "Base")
89 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080090 header = &registries::base::header;
91 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070092 }
93 else if (registry == "TaskEvent")
94 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080095 header = &registries::task_event::header;
96 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070097 }
98 else if (registry == "OpenBMC")
99 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800100 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700101 dmtf.clear();
102 }
103 else if (registry == "ResourceEvent")
104 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800105 header = &registries::resource_event::header;
106 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700107 }
108 else
109 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800110 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
111 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700112 return;
113 }
114
Ed Tanous14766872022-03-15 10:44:42 -0700115 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700116 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700117 asyncResp->res.jsonValue["@odata.type"] =
118 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
119 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williams89492a12023-05-10 07:51:34 -0500120 asyncResp->res.jsonValue["Description"] = dmtf + registry +
121 " Message Registry File Location";
Ed Tanous14766872022-03-15 10:44:42 -0700122 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
123 asyncResp->res.jsonValue["Registry"] = header->id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700124 nlohmann::json::array_t languages;
Patrick Williamsad539542023-05-12 10:10:08 -0500125 languages.emplace_back("en");
Ed Tanous613dabe2022-07-09 11:17:36 -0700126 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
127 asyncResp->res.jsonValue["Languages"] = std::move(languages);
128 nlohmann::json::array_t locationMembers;
129 nlohmann::json::object_t location;
130 location["Language"] = "en";
131 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700132
133 if (url != nullptr)
134 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700135 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700136 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700137 locationMembers.emplace_back(std::move(location));
138 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
139 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700140}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700141
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700142inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700143{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700144 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700145 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700146 .methods(boost::beast::http::verb::get)(std::bind_front(
147 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700149
John Edward Broadbentdff07822021-07-13 11:20:47 -0700150inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700151 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800152 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700153 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700154
John Edward Broadbentdff07822021-07-13 11:20:47 -0700155{
Carson Labrado3ba00072022-06-06 19:40:56 +0000156 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700157 {
158 return;
159 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800160 const registries::Header* header = nullptr;
161 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700162 if (registry == "Base")
163 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800164 header = &registries::base::header;
165 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700166 {
167 registryEntries.emplace_back(&entry);
168 }
169 }
170 else if (registry == "TaskEvent")
171 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800172 header = &registries::task_event::header;
173 for (const registries::MessageEntry& entry :
174 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700175 {
176 registryEntries.emplace_back(&entry);
177 }
178 }
179 else if (registry == "OpenBMC")
180 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800181 header = &registries::openbmc::header;
182 for (const registries::MessageEntry& entry :
183 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700184 {
185 registryEntries.emplace_back(&entry);
186 }
187 }
188 else if (registry == "ResourceEvent")
189 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800190 header = &registries::resource_event::header;
191 for (const registries::MessageEntry& entry :
192 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700193 {
194 registryEntries.emplace_back(&entry);
195 }
196 }
197 else
198 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800199 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
200 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700201 return;
202 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700203
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700204 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700205 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700206 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700207 return;
208 }
209
Ed Tanous14766872022-03-15 10:44:42 -0700210 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
211 asyncResp->res.jsonValue["@odata.type"] = header->type;
212 asyncResp->res.jsonValue["Id"] = header->id;
213 asyncResp->res.jsonValue["Name"] = header->name;
214 asyncResp->res.jsonValue["Language"] = header->language;
215 asyncResp->res.jsonValue["Description"] = header->description;
216 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
217 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
218 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700219
220 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
221
222 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800223 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700224 {
225 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700226 obj["Description"] = message->second.description;
227 obj["Message"] = message->second.message;
228 obj["Severity"] = message->second.messageSeverity;
229 obj["MessageSeverity"] = message->second.messageSeverity;
230 obj["NumberOfArgs"] = message->second.numberOfArgs;
231 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700232 if (message->second.numberOfArgs > 0)
233 {
234 nlohmann::json& messageParamArray = obj["ParamTypes"];
235 messageParamArray = nlohmann::json::array();
236 for (const char* str : message->second.paramTypes)
237 {
238 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700239 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700240 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700241 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700242 messageParamArray.push_back(str);
243 }
244 }
245 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700246}
247
248inline void requestRoutesMessageRegistry(App& app)
249{
250 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700251 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700252 .methods(boost::beast::http::verb::get)(
253 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700254}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700255} // namespace redfish