blob: e3bd5bf0b2f56db08a48caee63b223e1792f13ab [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 Broadbent7e860f12021-04-08 15:57:16 -070030inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070031{
Jason M. Bills70304cb2019-03-27 12:03:59 -070032 /**
33 * Functions triggers appropriate requests on DBus
34 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070035 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070036 .privileges(redfish::privileges::getMessageRegistryFileCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070037 .methods(boost::beast::http::verb::get)(
38 [](const crow::Request&,
39 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
40 // Collections don't include the static data added by SubRoute
41 // because it has a duplicate entry for members
Ed Tanous14c8aee2019-06-13 13:39:16 -070042
John Edward Broadbent7e860f12021-04-08 15:57:16 -070043 asyncResp->res.jsonValue = {
44 {"@odata.type", "#MessageRegistryFileCollection."
45 "MessageRegistryFileCollection"},
46 {"@odata.id", "/redfish/v1/Registries"},
47 {"Name", "MessageRegistryFile Collection"},
48 {"Description", "Collection of MessageRegistryFiles"},
49 {"Members@odata.count", 4},
50 {"Members",
51 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
52 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
53 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
54 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
55 });
56}
Jason M. Bills70304cb2019-03-27 12:03:59 -070057
John Edward Broadbent7e860f12021-04-08 15:57:16 -070058inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070059{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070060 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -070061 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070062 .methods(boost::beast::http::verb::get)(
63 [](const crow::Request&,
64 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
65 const std::string& registry) {
66 const message_registries::Header* header;
67 std::string dmtf = "DMTF ";
68 const char* url = nullptr;
Jason M. Bills70304cb2019-03-27 12:03:59 -070069
John Edward Broadbent7e860f12021-04-08 15:57:16 -070070 if (registry == "Base")
Jason M. Bills70304cb2019-03-27 12:03:59 -070071 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070072 header = &message_registries::base::header;
73 url = message_registries::base::url;
Jason M. Bills70304cb2019-03-27 12:03:59 -070074 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -070075 else if (registry == "TaskEvent")
76 {
77 header = &message_registries::task_event::header;
78 url = message_registries::task_event::url;
79 }
80 else if (registry == "OpenBMC")
81 {
82 header = &message_registries::openbmc::header;
83 dmtf.clear();
84 }
85 else if (registry == "ResourceEvent")
86 {
87 header = &message_registries::resource_event::header;
88 url = message_registries::resource_event::url;
89 }
90 else
91 {
92 messages::resourceNotFound(
93 asyncResp->res,
94 "#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",
102 "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
103 {"Name", registry + " Message Registry File"},
104 {"Description",
105 dmtf + registry + " Message Registry File Location"},
106 {"Id", header->registryPrefix},
107 {"Registry", header->id},
108 {"Languages", {"en"}},
109 {"Languages@odata.count", 1},
110 {"Location",
111 {{{"Language", "en"},
112 {"Uri", "/redfish/v1/Registries/" + registry + "/" +
113 registry}}}},
114 {"Location@odata.count", 1}};
115
116 if (url != nullptr)
117 {
118 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] =
119 url;
120 }
121 });
122}
123
124inline void requestRoutesMessageRegistry(App& app)
125{
126 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700127 .privileges(redfish::privileges::getMessageRegistryFile)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128 .methods(boost::beast::http::verb::get)(
129 [](const crow::Request&,
130 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
131 const std::string& registry, const std::string& registry1)
132
133 {
134 const message_registries::Header* header;
135 std::vector<const message_registries::MessageEntry*>
136 registryEntries;
137 if (registry == "Base")
138 {
139 header = &message_registries::base::header;
140 for (const message_registries::MessageEntry& entry :
141 message_registries::base::registry)
142 {
143 registryEntries.emplace_back(&entry);
144 }
145 }
146 else if (registry == "TaskEvent")
147 {
148 header = &message_registries::task_event::header;
149 for (const message_registries::MessageEntry& entry :
150 message_registries::task_event::registry)
151 {
152 registryEntries.emplace_back(&entry);
153 }
154 }
155 else if (registry == "OpenBMC")
156 {
157 header = &message_registries::openbmc::header;
158 for (const message_registries::MessageEntry& entry :
159 message_registries::openbmc::registry)
160 {
161 registryEntries.emplace_back(&entry);
162 }
163 }
164 else if (registry == "ResourceEvent")
165 {
166 header = &message_registries::resource_event::header;
167 for (const message_registries::MessageEntry& entry :
168 message_registries::resource_event::registry)
169 {
170 registryEntries.emplace_back(&entry);
171 }
172 }
173 else
174 {
175 messages::resourceNotFound(
176 asyncResp->res,
177 "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
178 registry);
179 return;
180 }
181
182 if (registry != registry1)
183 {
184 messages::resourceNotFound(asyncResp->res, header->type,
185 registry1);
186 return;
187 }
188
189 asyncResp->res.jsonValue = {
190 {"@Redfish.Copyright", header->copyright},
191 {"@odata.type", header->type},
192 {"Id", header->id},
193 {"Name", header->name},
194 {"Language", header->language},
195 {"Description", header->description},
196 {"RegistryPrefix", header->registryPrefix},
197 {"RegistryVersion", header->registryVersion},
198 {"OwningEntity", header->owningEntity}};
199
200 nlohmann::json& messageObj =
201 asyncResp->res.jsonValue["Messages"];
202
203 // Go through the Message Registry and populate each Message
204 for (const message_registries::MessageEntry* message :
205 registryEntries)
206 {
207 nlohmann::json& obj = messageObj[message->first];
208 obj = {{"Description", message->second.description},
209 {"Message", message->second.message},
210 {"Severity", message->second.severity},
211 {"MessageSeverity", message->second.messageSeverity},
212 {"NumberOfArgs", message->second.numberOfArgs},
213 {"Resolution", message->second.resolution}};
214 if (message->second.numberOfArgs > 0)
215 {
216 nlohmann::json& messageParamArray = obj["ParamTypes"];
Ed Tanous938f2562021-06-11 09:34:52 -0700217 messageParamArray = nlohmann::json::array();
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700218 for (const char* str : message->second.paramTypes)
219 {
220 if (str == nullptr)
221 {
222 break;
223 }
224 messageParamArray.push_back(str);
225 }
226 }
227 }
228 });
229}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700230
Jason M. Bills70304cb2019-03-27 12:03:59 -0700231} // namespace redfish