blob: 09d32b7d261b5b7ae58668d70bc94cb5a723df86 [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
Jason M. Bills70304cb2019-03-27 12:03:59 -070018#include "registries.hpp"
19#include "registries/base_message_registry.hpp"
Jason M. Billsfbe83782019-03-27 14:14:53 -070020#include "registries/openbmc_message_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050021#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070022#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070023
John Edward Broadbent7e860f12021-04-08 15:57:16 -070024#include <app.hpp>
Ed Tanous45ca1b82022-03-25 13:07:27 -070025#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070026#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -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";
48 asyncResp->res.jsonValue["Members@odata.count"] = 4;
49 asyncResp->res.jsonValue["Members"] = {
50 {{"@odata.id", "/redfish/v1/Registries/Base"}},
51 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
52 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
53 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}};
John Edward Broadbentdff07822021-07-13 11:20:47 -070054}
55
John Edward Broadbent7e860f12021-04-08 15:57:16 -070056inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070057{
Jason M. Bills70304cb2019-03-27 12:03:59 -070058 /**
59 * Functions triggers appropriate requests on DBus
60 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070061 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070062 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070063 .methods(boost::beast::http::verb::get)(std::bind_front(
64 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070065}
Ed Tanous14c8aee2019-06-13 13:39:16 -070066
John Edward Broadbentdff07822021-07-13 11:20:47 -070067inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070068 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080069 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070070 const std::string& registry)
71{
Carson Labrado3ba00072022-06-06 19:40:56 +000072 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070073 {
74 return;
75 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080076 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070077 std::string dmtf = "DMTF ";
78 const char* url = nullptr;
79
80 if (registry == "Base")
81 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080082 header = &registries::base::header;
83 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070084 }
85 else if (registry == "TaskEvent")
86 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080087 header = &registries::task_event::header;
88 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070089 }
90 else if (registry == "OpenBMC")
91 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080092 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -070093 dmtf.clear();
94 }
95 else if (registry == "ResourceEvent")
96 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080097 header = &registries::resource_event::header;
98 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070099 }
100 else
101 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800102 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
103 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700104 return;
105 }
106
Ed Tanous14766872022-03-15 10:44:42 -0700107 asyncResp->res.jsonValue["@odata.id"] =
108 "/redfish/v1/Registries/" + registry;
109 asyncResp->res.jsonValue["@odata.type"] =
110 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
111 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
112 asyncResp->res.jsonValue["Description"] =
113 dmtf + registry + " Message Registry File Location";
114 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
115 asyncResp->res.jsonValue["Registry"] = header->id;
116 asyncResp->res.jsonValue["Languages"] = {"en"};
117 asyncResp->res.jsonValue["Languages@odata.count"] = 1;
118 asyncResp->res.jsonValue["Location"] = {
119 {{"Language", "en"},
120 {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}};
121
122 asyncResp->res.jsonValue["Location@odata.count"] = 1;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700123
124 if (url != nullptr)
125 {
126 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
127 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700129
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700130inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700131{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700132 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700133 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700134 .methods(boost::beast::http::verb::get)(std::bind_front(
135 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700136}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700137
John Edward Broadbentdff07822021-07-13 11:20:47 -0700138inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700139 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800140 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700141 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700142
John Edward Broadbentdff07822021-07-13 11:20:47 -0700143{
Carson Labrado3ba00072022-06-06 19:40:56 +0000144 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700145 {
146 return;
147 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800148 const registries::Header* header = nullptr;
149 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700150 if (registry == "Base")
151 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800152 header = &registries::base::header;
153 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700154 {
155 registryEntries.emplace_back(&entry);
156 }
157 }
158 else if (registry == "TaskEvent")
159 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800160 header = &registries::task_event::header;
161 for (const registries::MessageEntry& entry :
162 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700163 {
164 registryEntries.emplace_back(&entry);
165 }
166 }
167 else if (registry == "OpenBMC")
168 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800169 header = &registries::openbmc::header;
170 for (const registries::MessageEntry& entry :
171 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700172 {
173 registryEntries.emplace_back(&entry);
174 }
175 }
176 else if (registry == "ResourceEvent")
177 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800178 header = &registries::resource_event::header;
179 for (const registries::MessageEntry& entry :
180 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700181 {
182 registryEntries.emplace_back(&entry);
183 }
184 }
185 else
186 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800187 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
188 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700189 return;
190 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700191
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700192 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700193 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700194 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700195 return;
196 }
197
Ed Tanous14766872022-03-15 10:44:42 -0700198 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
199 asyncResp->res.jsonValue["@odata.type"] = header->type;
200 asyncResp->res.jsonValue["Id"] = header->id;
201 asyncResp->res.jsonValue["Name"] = header->name;
202 asyncResp->res.jsonValue["Language"] = header->language;
203 asyncResp->res.jsonValue["Description"] = header->description;
204 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
205 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
206 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700207
208 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
209
210 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800211 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700212 {
213 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700214 obj["Description"] = message->second.description;
215 obj["Message"] = message->second.message;
216 obj["Severity"] = message->second.messageSeverity;
217 obj["MessageSeverity"] = message->second.messageSeverity;
218 obj["NumberOfArgs"] = message->second.numberOfArgs;
219 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700220 if (message->second.numberOfArgs > 0)
221 {
222 nlohmann::json& messageParamArray = obj["ParamTypes"];
223 messageParamArray = nlohmann::json::array();
224 for (const char* str : message->second.paramTypes)
225 {
226 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700227 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700228 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700229 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700230 messageParamArray.push_back(str);
231 }
232 }
233 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700234}
235
236inline void requestRoutesMessageRegistry(App& app)
237{
238 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700239 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700240 .methods(boost::beast::http::verb::get)(
241 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700242}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700243} // namespace redfish