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( |
| 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 Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame^] | 37 | {"@odata.type", |
| 38 | "#MessageRegistryFileCollection.MessageRegistryFileCollection"}, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 39 | {"@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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 50 | inline void requestRoutesMessageRegistryFileCollection(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 51 | { |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Functions triggers appropriate requests on DBus |
| 54 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 55 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 56 | .privileges(redfish::privileges::getMessageRegistryFileCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 57 | .methods(boost::beast::http::verb::get)( |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 58 | handleMessageRegistryFileCollectionGet); |
| 59 | } |
Ed Tanous | 14c8aee | 2019-06-13 13:39:16 -0700 | [diff] [blame] | 60 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 61 | inline void handleMessageRoutesMessageRegistryFileGet( |
| 62 | const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 63 | const std::string& registry) |
| 64 | { |
| 65 | const message_registries::Header* header; |
| 66 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 115 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 116 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 117 | inline void requestRoutesMessageRegistryFile(App& app) |
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 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 120 | .privileges(redfish::privileges::getMessageRegistryFile) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 121 | .methods(boost::beast::http::verb::get)( |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 122 | handleMessageRoutesMessageRegistryFileGet); |
| 123 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 124 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 125 | inline void handleMessageRegistryGet( |
| 126 | const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 127 | const std::string& registry, const std::string& registryMatch) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 128 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 129 | { |
| 130 | const message_registries::Header* header; |
| 131 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 175 | |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 176 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 177 | { |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 178 | messages::resourceNotFound(asyncResp->res, header->type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 179 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 211 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 212 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 213 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 214 | messageParamArray.push_back(str); |
| 215 | } |
| 216 | } |
| 217 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | inline void requestRoutesMessageRegistry(App& app) |
| 221 | { |
| 222 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 223 | .privileges(redfish::privileges::getMessageRegistryFile) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 224 | .methods(boost::beast::http::verb::get)(handleMessageRegistryGet); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 225 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 226 | } // namespace redfish |