blob: b8a3ebd526ea4272bad648ad0a761ba4511a8641 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2019 Intel Corporation
Jason M. Bills70304cb2019-03-27 12:03:59 -07004#pragma once
5
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "app.hpp"
7#include "query.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -07008#include "registries.hpp"
Myung Baef7a26072024-12-04 10:08:59 -06009#include "registries_selector.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070010
Ed Tanousef4c65b2023-04-24 15:28:50 -070011#include <boost/url/format.hpp>
12
Ed Tanous613dabe2022-07-09 11:17:36 -070013#include <array>
Ed Tanous56b81992024-12-02 10:36:37 -080014#include <format>
Ed Tanous613dabe2022-07-09 11:17:36 -070015
Jason M. Bills70304cb2019-03-27 12:03:59 -070016namespace redfish
17{
18
John Edward Broadbentdff07822021-07-13 11:20:47 -070019inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070020 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080021 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070022{
Carson Labrado3ba00072022-06-06 19:40:56 +000023 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070024 {
25 return;
26 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070027 // Collections don't include the static data added by SubRoute
28 // because it has a duplicate entry for members
29
Ed Tanous14766872022-03-15 10:44:42 -070030 asyncResp->res.jsonValue["@odata.type"] =
31 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
32 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
33 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
34 asyncResp->res.jsonValue["Description"] =
35 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070036
37 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050038
39 static constexpr const auto registryFiles = std::to_array(
40 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
41 "HeartbeatEvent"});
42
43 for (const char* memberName : registryFiles)
Ed Tanous613dabe2022-07-09 11:17:36 -070044 {
45 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040046 member["@odata.id"] =
47 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070048 members.emplace_back(std::move(member));
49 }
Myung Baefb546102024-10-29 10:21:26 -050050 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
John Edward Broadbentdff07822021-07-13 11:20:47 -070051}
52
John Edward Broadbent7e860f12021-04-08 15:57:16 -070053inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070054{
Jason M. Bills70304cb2019-03-27 12:03:59 -070055 /**
56 * Functions triggers appropriate requests on DBus
57 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070058 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070059 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070060 .methods(boost::beast::http::verb::get)(std::bind_front(
61 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070062}
Ed Tanous14c8aee2019-06-13 13:39:16 -070063
John Edward Broadbentdff07822021-07-13 11:20:47 -070064inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070065 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080066 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070067 const std::string& registry)
68{
Carson Labrado3ba00072022-06-06 19:40:56 +000069 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070070 {
71 return;
72 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070073 std::string dmtf = "DMTF ";
Myung Baef7a26072024-12-04 10:08:59 -060074 std::optional<registries::HeaderAndUrl> headerAndUrl =
75 registries::getRegistryHeaderAndUrlFromPrefix(registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070076
Myung Baef7a26072024-12-04 10:08:59 -060077 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -070078 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +080079 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
80 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070081 return;
82 }
Myung Baef7a26072024-12-04 10:08:59 -060083 if (registry == "OpenBMC")
84 {
85 dmtf.clear();
86 }
87 const registries::Header& header = headerAndUrl->header;
88 const char* url = headerAndUrl->url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070089
Ed Tanous14766872022-03-15 10:44:42 -070090 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070091 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -070092 asyncResp->res.jsonValue["@odata.type"] =
93 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
94 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -040095 asyncResp->res.jsonValue["Description"] =
96 dmtf + registry + " Message Registry File Location";
Myung Baef7a26072024-12-04 10:08:59 -060097 asyncResp->res.jsonValue["Id"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -080098 asyncResp->res.jsonValue["Registry"] =
99 std::format("{}.{}.{}", header.registryPrefix, header.versionMajor,
100 header.versionMinor);
Ed Tanous613dabe2022-07-09 11:17:36 -0700101 nlohmann::json::array_t languages;
Myung Baef7a26072024-12-04 10:08:59 -0600102 languages.emplace_back(header.language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700103 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
104 asyncResp->res.jsonValue["Languages"] = std::move(languages);
105 nlohmann::json::array_t locationMembers;
106 nlohmann::json::object_t location;
Myung Baef7a26072024-12-04 10:08:59 -0600107 location["Language"] = header.language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700108 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700109
110 if (url != nullptr)
111 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700112 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700113 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700114 locationMembers.emplace_back(std::move(location));
115 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
116 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700117}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700118
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700120{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700121 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700122 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700123 .methods(boost::beast::http::verb::get)(std::bind_front(
124 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700125}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700126
John Edward Broadbentdff07822021-07-13 11:20:47 -0700127inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700128 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800129 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700130 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700131
John Edward Broadbentdff07822021-07-13 11:20:47 -0700132{
Carson Labrado3ba00072022-06-06 19:40:56 +0000133 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700134 {
135 return;
136 }
Myung Baef7a26072024-12-04 10:08:59 -0600137
138 std::optional<registries::HeaderAndUrl> headerAndUrl =
139 registries::getRegistryHeaderAndUrlFromPrefix(registry);
140 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700141 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800142 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
143 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700144 return;
145 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700146
Myung Baef7a26072024-12-04 10:08:59 -0600147 const registries::Header& header = headerAndUrl->header;
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700148 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700149 {
Myung Baef7a26072024-12-04 10:08:59 -0600150 messages::resourceNotFound(asyncResp->res, header.type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700151 return;
152 }
153
Myung Baef7a26072024-12-04 10:08:59 -0600154 asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright;
155 asyncResp->res.jsonValue["@odata.type"] = header.type;
Ed Tanous56b81992024-12-02 10:36:37 -0800156 asyncResp->res.jsonValue["Id"] =
157 std::format("{}.{}.{}.{}", header.registryPrefix, header.versionMajor,
158 header.versionMinor, header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600159 asyncResp->res.jsonValue["Name"] = header.name;
160 asyncResp->res.jsonValue["Language"] = header.language;
161 asyncResp->res.jsonValue["Description"] = header.description;
162 asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800163 asyncResp->res.jsonValue["RegistryVersion"] =
164 std::format("{}.{}.{}", header.versionMajor, header.versionMinor,
165 header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600166 asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700167
168 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
169
170 // Go through the Message Registry and populate each Message
Myung Baef7a26072024-12-04 10:08:59 -0600171 const std::span<const registries::MessageEntry> registryEntries =
172 registries::getRegistryFromPrefix(registry);
173
174 for (const registries::MessageEntry& message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700175 {
Myung Baef7a26072024-12-04 10:08:59 -0600176 nlohmann::json& obj = messageObj[message.first];
177 obj["Description"] = message.second.description;
178 obj["Message"] = message.second.message;
179 obj["Severity"] = message.second.messageSeverity;
180 obj["MessageSeverity"] = message.second.messageSeverity;
181 obj["NumberOfArgs"] = message.second.numberOfArgs;
182 obj["Resolution"] = message.second.resolution;
183 if (message.second.numberOfArgs > 0)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700184 {
185 nlohmann::json& messageParamArray = obj["ParamTypes"];
186 messageParamArray = nlohmann::json::array();
Myung Baef7a26072024-12-04 10:08:59 -0600187 for (const char* str : message.second.paramTypes)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700188 {
189 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700190 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700191 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700192 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700193 messageParamArray.push_back(str);
194 }
195 }
196 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700197}
198
199inline void requestRoutesMessageRegistry(App& app)
200{
201 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700202 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700203 .methods(boost::beast::http::verb::get)(
204 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700205}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700206} // namespace redfish