blob: c030e5ae7ad9fdf7d52bea34be5a4842e3006ca7 [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 Tanoused398212021-06-09 17:05:54 -070025#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070026
Jason M. Bills70304cb2019-03-27 12:03:59 -070027namespace redfish
28{
29
John Edward Broadbentdff07822021-07-13 11:20:47 -070030inline void handleMessageRegistryFileCollectionGet(
Ed Tanous104f09c2022-01-25 09:56:04 -080031 const crow::Request& /*req*/,
32 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070033{
34 // Collections don't include the static data added by SubRoute
35 // because it has a duplicate entry for members
36
37 asyncResp->res.jsonValue = {
George Liu0fda0f12021-11-16 10:06:17 +080038 {"@odata.type",
39 "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
John Edward Broadbentdff07822021-07-13 11:20:47 -070040 {"@odata.id", "/redfish/v1/Registries"},
41 {"Name", "MessageRegistryFile Collection"},
42 {"Description", "Collection of MessageRegistryFiles"},
43 {"Members@odata.count", 4},
44 {"Members",
45 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
46 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
47 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
48 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
49}
50
John Edward Broadbent7e860f12021-04-08 15:57:16 -070051inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070052{
Jason M. Bills70304cb2019-03-27 12:03:59 -070053 /**
54 * Functions triggers appropriate requests on DBus
55 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070056 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070057 .privileges(redfish::privileges::getMessageRegistryFileCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070058 .methods(boost::beast::http::verb::get)(
John Edward Broadbentdff07822021-07-13 11:20:47 -070059 handleMessageRegistryFileCollectionGet);
60}
Ed Tanous14c8aee2019-06-13 13:39:16 -070061
John Edward Broadbentdff07822021-07-13 11:20:47 -070062inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous104f09c2022-01-25 09:56:04 -080063 const crow::Request& /*req*/,
64 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070065 const std::string& registry)
66{
Ed Tanousfffb8c12022-02-07 23:53:03 -080067 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070068 std::string dmtf = "DMTF ";
69 const char* url = nullptr;
70
71 if (registry == "Base")
72 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080073 header = &registries::base::header;
74 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070075 }
76 else if (registry == "TaskEvent")
77 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080078 header = &registries::task_event::header;
79 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070080 }
81 else if (registry == "OpenBMC")
82 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080083 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -070084 dmtf.clear();
85 }
86 else if (registry == "ResourceEvent")
87 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080088 header = &registries::resource_event::header;
89 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070090 }
91 else
92 {
93 messages::resourceNotFound(
94 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
95 registry);
96 return;
97 }
98
99 asyncResp->res.jsonValue = {
100 {"@odata.id", "/redfish/v1/Registries/" + registry},
101 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
102 {"Name", registry + " Message Registry File"},
103 {"Description", dmtf + registry + " Message Registry File Location"},
104 {"Id", header->registryPrefix},
105 {"Registry", header->id},
106 {"Languages", {"en"}},
107 {"Languages@odata.count", 1},
108 {"Location",
109 {{{"Language", "en"},
110 {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}},
111 {"Location@odata.count", 1}};
112
113 if (url != nullptr)
114 {
115 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
116 }
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)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700123 .methods(boost::beast::http::verb::get)(
John Edward Broadbentdff07822021-07-13 11:20:47 -0700124 handleMessageRoutesMessageRegistryFileGet);
125}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700126
John Edward Broadbentdff07822021-07-13 11:20:47 -0700127inline void handleMessageRegistryGet(
Ed Tanous104f09c2022-01-25 09:56:04 -0800128 const crow::Request& /*req*/,
129 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{
Ed Tanousfffb8c12022-02-07 23:53:03 -0800133 const registries::Header* header = nullptr;
134 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700135 if (registry == "Base")
136 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800137 header = &registries::base::header;
138 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700139 {
140 registryEntries.emplace_back(&entry);
141 }
142 }
143 else if (registry == "TaskEvent")
144 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800145 header = &registries::task_event::header;
146 for (const registries::MessageEntry& entry :
147 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148 {
149 registryEntries.emplace_back(&entry);
150 }
151 }
152 else if (registry == "OpenBMC")
153 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800154 header = &registries::openbmc::header;
155 for (const registries::MessageEntry& entry :
156 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700157 {
158 registryEntries.emplace_back(&entry);
159 }
160 }
161 else if (registry == "ResourceEvent")
162 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800163 header = &registries::resource_event::header;
164 for (const registries::MessageEntry& entry :
165 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700166 {
167 registryEntries.emplace_back(&entry);
168 }
169 }
170 else
171 {
172 messages::resourceNotFound(
173 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
174 registry);
175 return;
176 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700177
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700178 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700179 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700180 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700181 return;
182 }
183
184 asyncResp->res.jsonValue = {{"@Redfish.Copyright", header->copyright},
185 {"@odata.type", header->type},
186 {"Id", header->id},
187 {"Name", header->name},
188 {"Language", header->language},
189 {"Description", header->description},
190 {"RegistryPrefix", header->registryPrefix},
191 {"RegistryVersion", header->registryVersion},
192 {"OwningEntity", header->owningEntity}};
193
194 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
195
196 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800197 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700198 {
199 nlohmann::json& obj = messageObj[message->first];
200 obj = {{"Description", message->second.description},
201 {"Message", message->second.message},
Ed Tanous5f2b84e2022-02-08 00:41:53 -0800202 {"Severity", message->second.messageSeverity},
John Edward Broadbentdff07822021-07-13 11:20:47 -0700203 {"MessageSeverity", message->second.messageSeverity},
204 {"NumberOfArgs", message->second.numberOfArgs},
205 {"Resolution", message->second.resolution}};
206 if (message->second.numberOfArgs > 0)
207 {
208 nlohmann::json& messageParamArray = obj["ParamTypes"];
209 messageParamArray = nlohmann::json::array();
210 for (const char* str : message->second.paramTypes)
211 {
212 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700213 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700214 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700215 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700216 messageParamArray.push_back(str);
217 }
218 }
219 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700220}
221
222inline void requestRoutesMessageRegistry(App& app)
223{
224 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700225 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700226 .methods(boost::beast::http::verb::get)(handleMessageRegistryGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700227}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700228} // namespace redfish