blob: a6e108eb28374b9fb1199eeeb279c28b766f142d [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2019 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
Jason M. Bills70304cb2019-03-27 12:03:59 -070015*/
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"
Myung Baef7a26072024-12-04 10:08:59 -060021#include "registries_selector.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070022
Ed Tanousef4c65b2023-04-24 15:28:50 -070023#include <boost/url/format.hpp>
24
Ed Tanous613dabe2022-07-09 11:17:36 -070025#include <array>
26
Jason M. Bills70304cb2019-03-27 12:03:59 -070027namespace redfish
28{
29
John Edward Broadbentdff07822021-07-13 11:20:47 -070030inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070031 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080032 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070033{
Carson Labrado3ba00072022-06-06 19:40:56 +000034 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070035 {
36 return;
37 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070038 // Collections don't include the static data added by SubRoute
39 // because it has a duplicate entry for members
40
Ed Tanous14766872022-03-15 10:44:42 -070041 asyncResp->res.jsonValue["@odata.type"] =
42 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
43 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
44 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
45 asyncResp->res.jsonValue["Description"] =
46 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070047
48 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050049
50 static constexpr const auto registryFiles = std::to_array(
51 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
52 "HeartbeatEvent"});
53
54 for (const char* memberName : registryFiles)
Ed Tanous613dabe2022-07-09 11:17:36 -070055 {
56 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040057 member["@odata.id"] =
58 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070059 members.emplace_back(std::move(member));
60 }
Myung Baefb546102024-10-29 10:21:26 -050061 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
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 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070084 std::string dmtf = "DMTF ";
Myung Baef7a26072024-12-04 10:08:59 -060085 std::optional<registries::HeaderAndUrl> headerAndUrl =
86 registries::getRegistryHeaderAndUrlFromPrefix(registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070087
Myung Baef7a26072024-12-04 10:08:59 -060088 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -070089 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +080090 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
91 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070092 return;
93 }
Myung Baef7a26072024-12-04 10:08:59 -060094 if (registry == "OpenBMC")
95 {
96 dmtf.clear();
97 }
98 const registries::Header& header = headerAndUrl->header;
99 const char* url = headerAndUrl->url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700100
Ed Tanous14766872022-03-15 10:44:42 -0700101 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700102 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700103 asyncResp->res.jsonValue["@odata.type"] =
104 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
105 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400106 asyncResp->res.jsonValue["Description"] =
107 dmtf + registry + " Message Registry File Location";
Myung Baef7a26072024-12-04 10:08:59 -0600108 asyncResp->res.jsonValue["Id"] = header.registryPrefix;
109 asyncResp->res.jsonValue["Registry"] = header.id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700110 nlohmann::json::array_t languages;
Myung Baef7a26072024-12-04 10:08:59 -0600111 languages.emplace_back(header.language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700112 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
113 asyncResp->res.jsonValue["Languages"] = std::move(languages);
114 nlohmann::json::array_t locationMembers;
115 nlohmann::json::object_t location;
Myung Baef7a26072024-12-04 10:08:59 -0600116 location["Language"] = header.language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700117 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700118
119 if (url != nullptr)
120 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700121 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700122 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700123 locationMembers.emplace_back(std::move(location));
124 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
125 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700126}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700127
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700129{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700130 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700131 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700132 .methods(boost::beast::http::verb::get)(std::bind_front(
133 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700134}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700135
John Edward Broadbentdff07822021-07-13 11:20:47 -0700136inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700137 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800138 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700139 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700140
John Edward Broadbentdff07822021-07-13 11:20:47 -0700141{
Carson Labrado3ba00072022-06-06 19:40:56 +0000142 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700143 {
144 return;
145 }
Myung Baef7a26072024-12-04 10:08:59 -0600146
147 std::optional<registries::HeaderAndUrl> headerAndUrl =
148 registries::getRegistryHeaderAndUrlFromPrefix(registry);
149 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700150 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800151 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
152 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700153 return;
154 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700155
Myung Baef7a26072024-12-04 10:08:59 -0600156 const registries::Header& header = headerAndUrl->header;
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700157 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700158 {
Myung Baef7a26072024-12-04 10:08:59 -0600159 messages::resourceNotFound(asyncResp->res, header.type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700160 return;
161 }
162
Myung Baef7a26072024-12-04 10:08:59 -0600163 asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright;
164 asyncResp->res.jsonValue["@odata.type"] = header.type;
165 asyncResp->res.jsonValue["Id"] = header.id;
166 asyncResp->res.jsonValue["Name"] = header.name;
167 asyncResp->res.jsonValue["Language"] = header.language;
168 asyncResp->res.jsonValue["Description"] = header.description;
169 asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix;
170 asyncResp->res.jsonValue["RegistryVersion"] = header.registryVersion;
171 asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700172
173 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
174
175 // Go through the Message Registry and populate each Message
Myung Baef7a26072024-12-04 10:08:59 -0600176 const std::span<const registries::MessageEntry> registryEntries =
177 registries::getRegistryFromPrefix(registry);
178
179 for (const registries::MessageEntry& message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700180 {
Myung Baef7a26072024-12-04 10:08:59 -0600181 nlohmann::json& obj = messageObj[message.first];
182 obj["Description"] = message.second.description;
183 obj["Message"] = message.second.message;
184 obj["Severity"] = message.second.messageSeverity;
185 obj["MessageSeverity"] = message.second.messageSeverity;
186 obj["NumberOfArgs"] = message.second.numberOfArgs;
187 obj["Resolution"] = message.second.resolution;
188 if (message.second.numberOfArgs > 0)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700189 {
190 nlohmann::json& messageParamArray = obj["ParamTypes"];
191 messageParamArray = nlohmann::json::array();
Myung Baef7a26072024-12-04 10:08:59 -0600192 for (const char* str : message.second.paramTypes)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700193 {
194 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700195 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700196 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700197 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700198 messageParamArray.push_back(str);
199 }
200 }
201 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700202}
203
204inline void requestRoutesMessageRegistry(App& app)
205{
206 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700207 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700208 .methods(boost::beast::http::verb::get)(
209 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700210}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700211} // namespace redfish