Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 1 | /* |
| 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. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 18 | #include "registries.hpp" |
| 19 | #include "registries/base_message_registry.hpp" |
Jason M. Bills | fbe8378 | 2019-03-27 14:14:53 -0700 | [diff] [blame] | 20 | #include "registries/openbmc_message_registry.hpp" |
Sunitha Harish | 74eec26 | 2020-06-25 10:00:01 -0500 | [diff] [blame] | 21 | #include "registries/resource_event_message_registry.hpp" |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 22 | #include "registries/task_event_message_registry.hpp" |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 23 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 24 | #include <app.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 25 | #include <registries/privilege_registry.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 26 | |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 27 | namespace redfish |
| 28 | { |
| 29 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 30 | inline void handleMessageRegistryFileCollectionGet( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 31 | const crow::Request& /*req*/, |
| 32 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 33 | { |
| 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 Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 38 | {"@odata.type", |
| 39 | "#MessageRegistryFileCollection.MessageRegistryFileCollection"}, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 40 | {"@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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 51 | inline void requestRoutesMessageRegistryFileCollection(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 52 | { |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Functions triggers appropriate requests on DBus |
| 55 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 56 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 57 | .privileges(redfish::privileges::getMessageRegistryFileCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 58 | .methods(boost::beast::http::verb::get)( |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 59 | handleMessageRegistryFileCollectionGet); |
| 60 | } |
Ed Tanous | 14c8aee | 2019-06-13 13:39:16 -0700 | [diff] [blame] | 61 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 62 | inline void handleMessageRoutesMessageRegistryFileGet( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 63 | const crow::Request& /*req*/, |
| 64 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 65 | const std::string& registry) |
| 66 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 67 | const message_registries::Header* header = nullptr; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 68 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 117 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 118 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 119 | inline void requestRoutesMessageRegistryFile(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 120 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 121 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 122 | .privileges(redfish::privileges::getMessageRegistryFile) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 123 | .methods(boost::beast::http::verb::get)( |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 124 | handleMessageRoutesMessageRegistryFileGet); |
| 125 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 126 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 127 | inline void handleMessageRegistryGet( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 128 | const crow::Request& /*req*/, |
| 129 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 130 | const std::string& registry, const std::string& registryMatch) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 131 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 132 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 133 | const message_registries::Header* header = nullptr; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 134 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 178 | |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 179 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 180 | { |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 181 | messages::resourceNotFound(asyncResp->res, header->type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 182 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 214 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 215 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 216 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 217 | messageParamArray.push_back(str); |
| 218 | } |
| 219 | } |
| 220 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | inline void requestRoutesMessageRegistry(App& app) |
| 224 | { |
| 225 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 226 | .privileges(redfish::privileges::getMessageRegistryFile) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 227 | .methods(boost::beast::http::verb::get)(handleMessageRegistryGet); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 228 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 229 | } // namespace redfish |