blob: fe4c592006072d79c8328ae4b34a19c266c51134 [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{
Ed Tanous45ca1b82022-03-25 13:07:27 -070035 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
36 {
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
42 asyncResp->res.jsonValue = {
George Liu0fda0f12021-11-16 10:06:17 +080043 {"@odata.type",
44 "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
John Edward Broadbentdff07822021-07-13 11:20:47 -070045 {"@odata.id", "/redfish/v1/Registries"},
46 {"Name", "MessageRegistryFile Collection"},
47 {"Description", "Collection of MessageRegistryFiles"},
48 {"Members@odata.count", 4},
49 {"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"}}}}};
54}
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{
Ed Tanous45ca1b82022-03-25 13:07:27 -070072 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
73 {
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
108 asyncResp->res.jsonValue = {
109 {"@odata.id", "/redfish/v1/Registries/" + registry},
110 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
111 {"Name", registry + " Message Registry File"},
112 {"Description", dmtf + registry + " Message Registry File Location"},
113 {"Id", header->registryPrefix},
114 {"Registry", header->id},
115 {"Languages", {"en"}},
116 {"Languages@odata.count", 1},
117 {"Location",
118 {{{"Language", "en"},
119 {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}},
120 {"Location@odata.count", 1}};
121
122 if (url != nullptr)
123 {
124 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
125 }
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{
Ed Tanous45ca1b82022-03-25 13:07:27 -0700142 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
143 {
144 return;
145 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800146 const registries::Header* header = nullptr;
147 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148 if (registry == "Base")
149 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800150 header = &registries::base::header;
151 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700152 {
153 registryEntries.emplace_back(&entry);
154 }
155 }
156 else if (registry == "TaskEvent")
157 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800158 header = &registries::task_event::header;
159 for (const registries::MessageEntry& entry :
160 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700161 {
162 registryEntries.emplace_back(&entry);
163 }
164 }
165 else if (registry == "OpenBMC")
166 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800167 header = &registries::openbmc::header;
168 for (const registries::MessageEntry& entry :
169 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700170 {
171 registryEntries.emplace_back(&entry);
172 }
173 }
174 else if (registry == "ResourceEvent")
175 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800176 header = &registries::resource_event::header;
177 for (const registries::MessageEntry& entry :
178 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700179 {
180 registryEntries.emplace_back(&entry);
181 }
182 }
183 else
184 {
185 messages::resourceNotFound(
186 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
187 registry);
188 return;
189 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700190
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700191 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700192 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700193 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700194 return;
195 }
196
197 asyncResp->res.jsonValue = {{"@Redfish.Copyright", header->copyright},
198 {"@odata.type", header->type},
199 {"Id", header->id},
200 {"Name", header->name},
201 {"Language", header->language},
202 {"Description", header->description},
203 {"RegistryPrefix", header->registryPrefix},
204 {"RegistryVersion", header->registryVersion},
205 {"OwningEntity", header->owningEntity}};
206
207 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
208
209 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800210 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700211 {
212 nlohmann::json& obj = messageObj[message->first];
213 obj = {{"Description", message->second.description},
214 {"Message", message->second.message},
Ed Tanous5f2b84e2022-02-08 00:41:53 -0800215 {"Severity", message->second.messageSeverity},
John Edward Broadbentdff07822021-07-13 11:20:47 -0700216 {"MessageSeverity", message->second.messageSeverity},
217 {"NumberOfArgs", message->second.numberOfArgs},
218 {"Resolution", message->second.resolution}};
219 if (message->second.numberOfArgs > 0)
220 {
221 nlohmann::json& messageParamArray = obj["ParamTypes"];
222 messageParamArray = nlohmann::json::array();
223 for (const char* str : message->second.paramTypes)
224 {
225 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700226 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700227 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700228 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700229 messageParamArray.push_back(str);
230 }
231 }
232 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700233}
234
235inline void requestRoutesMessageRegistry(App& app)
236{
237 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700238 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700239 .methods(boost::beast::http::verb::get)(
240 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700241}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700242} // namespace redfish