blob: b327d63f150a79f4768fe9b1ff346e78e46e55bd [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>
Ed Tanous56b81992024-12-02 10:36:37 -080026#include <format>
Ed Tanous613dabe2022-07-09 11:17:36 -070027
Jason M. Bills70304cb2019-03-27 12:03:59 -070028namespace redfish
29{
30
John Edward Broadbentdff07822021-07-13 11:20:47 -070031inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070032 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080033 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070034{
Carson Labrado3ba00072022-06-06 19:40:56 +000035 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070036 {
37 return;
38 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070039 // Collections don't include the static data added by SubRoute
40 // because it has a duplicate entry for members
41
Ed Tanous14766872022-03-15 10:44:42 -070042 asyncResp->res.jsonValue["@odata.type"] =
43 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
44 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
45 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
46 asyncResp->res.jsonValue["Description"] =
47 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070048
49 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050050
51 static constexpr const auto registryFiles = std::to_array(
52 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
53 "HeartbeatEvent"});
54
55 for (const char* memberName : registryFiles)
Ed Tanous613dabe2022-07-09 11:17:36 -070056 {
57 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040058 member["@odata.id"] =
59 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070060 members.emplace_back(std::move(member));
61 }
Myung Baefb546102024-10-29 10:21:26 -050062 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
John Edward Broadbentdff07822021-07-13 11:20:47 -070063}
64
John Edward Broadbent7e860f12021-04-08 15:57:16 -070065inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070066{
Jason M. Bills70304cb2019-03-27 12:03:59 -070067 /**
68 * Functions triggers appropriate requests on DBus
69 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070070 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070071 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070072 .methods(boost::beast::http::verb::get)(std::bind_front(
73 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070074}
Ed Tanous14c8aee2019-06-13 13:39:16 -070075
John Edward Broadbentdff07822021-07-13 11:20:47 -070076inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070077 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080078 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070079 const std::string& registry)
80{
Carson Labrado3ba00072022-06-06 19:40:56 +000081 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070082 {
83 return;
84 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070085 std::string dmtf = "DMTF ";
Myung Baef7a26072024-12-04 10:08:59 -060086 std::optional<registries::HeaderAndUrl> headerAndUrl =
87 registries::getRegistryHeaderAndUrlFromPrefix(registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070088
Myung Baef7a26072024-12-04 10:08:59 -060089 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -070090 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +080091 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
92 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070093 return;
94 }
Myung Baef7a26072024-12-04 10:08:59 -060095 if (registry == "OpenBMC")
96 {
97 dmtf.clear();
98 }
99 const registries::Header& header = headerAndUrl->header;
100 const char* url = headerAndUrl->url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700101
Ed Tanous14766872022-03-15 10:44:42 -0700102 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700103 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700104 asyncResp->res.jsonValue["@odata.type"] =
105 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
106 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400107 asyncResp->res.jsonValue["Description"] =
108 dmtf + registry + " Message Registry File Location";
Myung Baef7a26072024-12-04 10:08:59 -0600109 asyncResp->res.jsonValue["Id"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800110 asyncResp->res.jsonValue["Registry"] =
111 std::format("{}.{}.{}", header.registryPrefix, header.versionMajor,
112 header.versionMinor);
Ed Tanous613dabe2022-07-09 11:17:36 -0700113 nlohmann::json::array_t languages;
Myung Baef7a26072024-12-04 10:08:59 -0600114 languages.emplace_back(header.language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700115 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
116 asyncResp->res.jsonValue["Languages"] = std::move(languages);
117 nlohmann::json::array_t locationMembers;
118 nlohmann::json::object_t location;
Myung Baef7a26072024-12-04 10:08:59 -0600119 location["Language"] = header.language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700120 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700121
122 if (url != nullptr)
123 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700124 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700125 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700126 locationMembers.emplace_back(std::move(location));
127 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
128 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700129}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700130
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700131inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700132{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700133 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700134 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700135 .methods(boost::beast::http::verb::get)(std::bind_front(
136 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700137}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700138
John Edward Broadbentdff07822021-07-13 11:20:47 -0700139inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700140 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800141 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700142 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700143
John Edward Broadbentdff07822021-07-13 11:20:47 -0700144{
Carson Labrado3ba00072022-06-06 19:40:56 +0000145 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700146 {
147 return;
148 }
Myung Baef7a26072024-12-04 10:08:59 -0600149
150 std::optional<registries::HeaderAndUrl> headerAndUrl =
151 registries::getRegistryHeaderAndUrlFromPrefix(registry);
152 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700153 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800154 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
155 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700156 return;
157 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700158
Myung Baef7a26072024-12-04 10:08:59 -0600159 const registries::Header& header = headerAndUrl->header;
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700160 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700161 {
Myung Baef7a26072024-12-04 10:08:59 -0600162 messages::resourceNotFound(asyncResp->res, header.type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700163 return;
164 }
165
Myung Baef7a26072024-12-04 10:08:59 -0600166 asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright;
167 asyncResp->res.jsonValue["@odata.type"] = header.type;
Ed Tanous56b81992024-12-02 10:36:37 -0800168 asyncResp->res.jsonValue["Id"] =
169 std::format("{}.{}.{}.{}", header.registryPrefix, header.versionMajor,
170 header.versionMinor, header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600171 asyncResp->res.jsonValue["Name"] = header.name;
172 asyncResp->res.jsonValue["Language"] = header.language;
173 asyncResp->res.jsonValue["Description"] = header.description;
174 asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800175 asyncResp->res.jsonValue["RegistryVersion"] =
176 std::format("{}.{}.{}", header.versionMajor, header.versionMinor,
177 header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600178 asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700179
180 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
181
182 // Go through the Message Registry and populate each Message
Myung Baef7a26072024-12-04 10:08:59 -0600183 const std::span<const registries::MessageEntry> registryEntries =
184 registries::getRegistryFromPrefix(registry);
185
186 for (const registries::MessageEntry& message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700187 {
Myung Baef7a26072024-12-04 10:08:59 -0600188 nlohmann::json& obj = messageObj[message.first];
189 obj["Description"] = message.second.description;
190 obj["Message"] = message.second.message;
191 obj["Severity"] = message.second.messageSeverity;
192 obj["MessageSeverity"] = message.second.messageSeverity;
193 obj["NumberOfArgs"] = message.second.numberOfArgs;
194 obj["Resolution"] = message.second.resolution;
195 if (message.second.numberOfArgs > 0)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700196 {
197 nlohmann::json& messageParamArray = obj["ParamTypes"];
198 messageParamArray = nlohmann::json::array();
Myung Baef7a26072024-12-04 10:08:59 -0600199 for (const char* str : message.second.paramTypes)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700200 {
201 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700202 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700203 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700204 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700205 messageParamArray.push_back(str);
206 }
207 }
208 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700209}
210
211inline void requestRoutesMessageRegistry(App& app)
212{
213 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700214 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700215 .methods(boost::beast::http::verb::get)(
216 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700217}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700218} // namespace redfish