blob: c2848c398b9e9df9e0b1643c3c455f1044ff9469 [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 Tanous543f4402022-01-06 13:12:53 -080067 const message_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 {
73 header = &message_registries::base::header;
74 url = message_registries::base::url;
75 }
76 else if (registry == "TaskEvent")
77 {
78 header = &message_registries::task_event::header;
79 url = message_registries::task_event::url;
80 }
81 else if (registry == "OpenBMC")
82 {
83 header = &message_registries::openbmc::header;
84 dmtf.clear();
85 }
86 else if (registry == "ResourceEvent")
87 {
88 header = &message_registries::resource_event::header;
89 url = message_registries::resource_event::url;
90 }
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 Tanous543f4402022-01-06 13:12:53 -0800133 const message_registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700134 std::vector<const message_registries::MessageEntry*> registryEntries;
135 if (registry == "Base")
136 {
137 header = &message_registries::base::header;
138 for (const message_registries::MessageEntry& entry :
139 message_registries::base::registry)
140 {
141 registryEntries.emplace_back(&entry);
142 }
143 }
144 else if (registry == "TaskEvent")
145 {
146 header = &message_registries::task_event::header;
147 for (const message_registries::MessageEntry& entry :
148 message_registries::task_event::registry)
149 {
150 registryEntries.emplace_back(&entry);
151 }
152 }
153 else if (registry == "OpenBMC")
154 {
155 header = &message_registries::openbmc::header;
156 for (const message_registries::MessageEntry& entry :
157 message_registries::openbmc::registry)
158 {
159 registryEntries.emplace_back(&entry);
160 }
161 }
162 else if (registry == "ResourceEvent")
163 {
164 header = &message_registries::resource_event::header;
165 for (const message_registries::MessageEntry& entry :
166 message_registries::resource_event::registry)
167 {
168 registryEntries.emplace_back(&entry);
169 }
170 }
171 else
172 {
173 messages::resourceNotFound(
174 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
175 registry);
176 return;
177 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700178
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700179 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700180 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700181 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700182 return;
183 }
184
185 asyncResp->res.jsonValue = {{"@Redfish.Copyright", header->copyright},
186 {"@odata.type", header->type},
187 {"Id", header->id},
188 {"Name", header->name},
189 {"Language", header->language},
190 {"Description", header->description},
191 {"RegistryPrefix", header->registryPrefix},
192 {"RegistryVersion", header->registryVersion},
193 {"OwningEntity", header->owningEntity}};
194
195 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
196
197 // Go through the Message Registry and populate each Message
198 for (const message_registries::MessageEntry* message : registryEntries)
199 {
200 nlohmann::json& obj = messageObj[message->first];
201 obj = {{"Description", message->second.description},
202 {"Message", message->second.message},
203 {"Severity", message->second.severity},
204 {"MessageSeverity", message->second.messageSeverity},
205 {"NumberOfArgs", message->second.numberOfArgs},
206 {"Resolution", message->second.resolution}};
207 if (message->second.numberOfArgs > 0)
208 {
209 nlohmann::json& messageParamArray = obj["ParamTypes"];
210 messageParamArray = nlohmann::json::array();
211 for (const char* str : message->second.paramTypes)
212 {
213 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700214 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700215 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700216 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700217 messageParamArray.push_back(str);
218 }
219 }
220 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700221}
222
223inline void requestRoutesMessageRegistry(App& app)
224{
225 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700226 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700227 .methods(boost::beast::http::verb::get)(handleMessageRegistryGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700228}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700229} // namespace redfish