blob: 189cd2e75c93d0a2caa2067022915e72c9c1dbda [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 {
102 messages::resourceNotFound(
103 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
104 registry);
105 return;
106 }
107
Ed Tanous14766872022-03-15 10:44:42 -0700108 asyncResp->res.jsonValue["@odata.id"] =
109 "/redfish/v1/Registries/" + registry;
110 asyncResp->res.jsonValue["@odata.type"] =
111 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
112 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
113 asyncResp->res.jsonValue["Description"] =
114 dmtf + registry + " Message Registry File Location";
115 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
116 asyncResp->res.jsonValue["Registry"] = header->id;
117 asyncResp->res.jsonValue["Languages"] = {"en"};
118 asyncResp->res.jsonValue["Languages@odata.count"] = 1;
119 asyncResp->res.jsonValue["Location"] = {
120 {{"Language", "en"},
121 {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}};
122
123 asyncResp->res.jsonValue["Location@odata.count"] = 1;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700124
125 if (url != nullptr)
126 {
127 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
128 }
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 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800149 const registries::Header* header = nullptr;
150 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700151 if (registry == "Base")
152 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800153 header = &registries::base::header;
154 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700155 {
156 registryEntries.emplace_back(&entry);
157 }
158 }
159 else if (registry == "TaskEvent")
160 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800161 header = &registries::task_event::header;
162 for (const registries::MessageEntry& entry :
163 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700164 {
165 registryEntries.emplace_back(&entry);
166 }
167 }
168 else if (registry == "OpenBMC")
169 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800170 header = &registries::openbmc::header;
171 for (const registries::MessageEntry& entry :
172 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700173 {
174 registryEntries.emplace_back(&entry);
175 }
176 }
177 else if (registry == "ResourceEvent")
178 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800179 header = &registries::resource_event::header;
180 for (const registries::MessageEntry& entry :
181 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700182 {
183 registryEntries.emplace_back(&entry);
184 }
185 }
186 else
187 {
188 messages::resourceNotFound(
189 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
190 registry);
191 return;
192 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700193
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700194 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700195 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700196 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700197 return;
198 }
199
Ed Tanous14766872022-03-15 10:44:42 -0700200 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
201 asyncResp->res.jsonValue["@odata.type"] = header->type;
202 asyncResp->res.jsonValue["Id"] = header->id;
203 asyncResp->res.jsonValue["Name"] = header->name;
204 asyncResp->res.jsonValue["Language"] = header->language;
205 asyncResp->res.jsonValue["Description"] = header->description;
206 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
207 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
208 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700209
210 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
211
212 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800213 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700214 {
215 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700216 obj["Description"] = message->second.description;
217 obj["Message"] = message->second.message;
218 obj["Severity"] = message->second.messageSeverity;
219 obj["MessageSeverity"] = message->second.messageSeverity;
220 obj["NumberOfArgs"] = message->second.numberOfArgs;
221 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700222 if (message->second.numberOfArgs > 0)
223 {
224 nlohmann::json& messageParamArray = obj["ParamTypes"];
225 messageParamArray = nlohmann::json::array();
226 for (const char* str : message->second.paramTypes)
227 {
228 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700229 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700230 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700231 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700232 messageParamArray.push_back(str);
233 }
234 }
235 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700236}
237
238inline void requestRoutesMessageRegistry(App& app)
239{
240 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700241 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700242 .methods(boost::beast::http::verb::get)(
243 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700244}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700245} // namespace redfish