blob: cfa2bf574f77005f97b78e1bef76fa03eccdee0a [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(
31 const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
32{
33 // Collections don't include the static data added by SubRoute
34 // because it has a duplicate entry for members
35
36 asyncResp->res.jsonValue = {
George Liu0fda0f12021-11-16 10:06:17 +080037 {"@odata.type",
38 "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
John Edward Broadbentdff07822021-07-13 11:20:47 -070039 {"@odata.id", "/redfish/v1/Registries"},
40 {"Name", "MessageRegistryFile Collection"},
41 {"Description", "Collection of MessageRegistryFiles"},
42 {"Members@odata.count", 4},
43 {"Members",
44 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
45 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
46 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
47 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
48}
49
John Edward Broadbent7e860f12021-04-08 15:57:16 -070050inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070051{
Jason M. Bills70304cb2019-03-27 12:03:59 -070052 /**
53 * Functions triggers appropriate requests on DBus
54 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070055 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070056 .privileges(redfish::privileges::getMessageRegistryFileCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070057 .methods(boost::beast::http::verb::get)(
John Edward Broadbentdff07822021-07-13 11:20:47 -070058 handleMessageRegistryFileCollectionGet);
59}
Ed Tanous14c8aee2019-06-13 13:39:16 -070060
John Edward Broadbentdff07822021-07-13 11:20:47 -070061inline void handleMessageRoutesMessageRegistryFileGet(
62 const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
63 const std::string& registry)
64{
Ed Tanous543f4402022-01-06 13:12:53 -080065 const message_registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070066 std::string dmtf = "DMTF ";
67 const char* url = nullptr;
68
69 if (registry == "Base")
70 {
71 header = &message_registries::base::header;
72 url = message_registries::base::url;
73 }
74 else if (registry == "TaskEvent")
75 {
76 header = &message_registries::task_event::header;
77 url = message_registries::task_event::url;
78 }
79 else if (registry == "OpenBMC")
80 {
81 header = &message_registries::openbmc::header;
82 dmtf.clear();
83 }
84 else if (registry == "ResourceEvent")
85 {
86 header = &message_registries::resource_event::header;
87 url = message_registries::resource_event::url;
88 }
89 else
90 {
91 messages::resourceNotFound(
92 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
93 registry);
94 return;
95 }
96
97 asyncResp->res.jsonValue = {
98 {"@odata.id", "/redfish/v1/Registries/" + registry},
99 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
100 {"Name", registry + " Message Registry File"},
101 {"Description", dmtf + registry + " Message Registry File Location"},
102 {"Id", header->registryPrefix},
103 {"Registry", header->id},
104 {"Languages", {"en"}},
105 {"Languages@odata.count", 1},
106 {"Location",
107 {{{"Language", "en"},
108 {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}},
109 {"Location@odata.count", 1}};
110
111 if (url != nullptr)
112 {
113 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
114 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700115}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700116
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700117inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700118{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700120 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700121 .methods(boost::beast::http::verb::get)(
John Edward Broadbentdff07822021-07-13 11:20:47 -0700122 handleMessageRoutesMessageRegistryFileGet);
123}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700124
John Edward Broadbentdff07822021-07-13 11:20:47 -0700125inline void handleMessageRegistryGet(
126 const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700127 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128
John Edward Broadbentdff07822021-07-13 11:20:47 -0700129{
Ed Tanous543f4402022-01-06 13:12:53 -0800130 const message_registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700131 std::vector<const message_registries::MessageEntry*> registryEntries;
132 if (registry == "Base")
133 {
134 header = &message_registries::base::header;
135 for (const message_registries::MessageEntry& entry :
136 message_registries::base::registry)
137 {
138 registryEntries.emplace_back(&entry);
139 }
140 }
141 else if (registry == "TaskEvent")
142 {
143 header = &message_registries::task_event::header;
144 for (const message_registries::MessageEntry& entry :
145 message_registries::task_event::registry)
146 {
147 registryEntries.emplace_back(&entry);
148 }
149 }
150 else if (registry == "OpenBMC")
151 {
152 header = &message_registries::openbmc::header;
153 for (const message_registries::MessageEntry& entry :
154 message_registries::openbmc::registry)
155 {
156 registryEntries.emplace_back(&entry);
157 }
158 }
159 else if (registry == "ResourceEvent")
160 {
161 header = &message_registries::resource_event::header;
162 for (const message_registries::MessageEntry& entry :
163 message_registries::resource_event::registry)
164 {
165 registryEntries.emplace_back(&entry);
166 }
167 }
168 else
169 {
170 messages::resourceNotFound(
171 asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
172 registry);
173 return;
174 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700175
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700176 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700177 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700178 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700179 return;
180 }
181
182 asyncResp->res.jsonValue = {{"@Redfish.Copyright", header->copyright},
183 {"@odata.type", header->type},
184 {"Id", header->id},
185 {"Name", header->name},
186 {"Language", header->language},
187 {"Description", header->description},
188 {"RegistryPrefix", header->registryPrefix},
189 {"RegistryVersion", header->registryVersion},
190 {"OwningEntity", header->owningEntity}};
191
192 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
193
194 // Go through the Message Registry and populate each Message
195 for (const message_registries::MessageEntry* message : registryEntries)
196 {
197 nlohmann::json& obj = messageObj[message->first];
198 obj = {{"Description", message->second.description},
199 {"Message", message->second.message},
200 {"Severity", message->second.severity},
201 {"MessageSeverity", message->second.messageSeverity},
202 {"NumberOfArgs", message->second.numberOfArgs},
203 {"Resolution", message->second.resolution}};
204 if (message->second.numberOfArgs > 0)
205 {
206 nlohmann::json& messageParamArray = obj["ParamTypes"];
207 messageParamArray = nlohmann::json::array();
208 for (const char* str : message->second.paramTypes)
209 {
210 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700211 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700212 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700213 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700214 messageParamArray.push_back(str);
215 }
216 }
217 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700218}
219
220inline void requestRoutesMessageRegistry(App& app)
221{
222 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700223 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700224 .methods(boost::beast::http::verb::get)(handleMessageRegistryGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700225}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700226} // namespace redfish