1 #include "registries.hpp" 2 3 #include "registries/base_message_registry.hpp" 4 #include "registries/openbmc_message_registry.hpp" 5 #include "str_utility.hpp" 6 7 #include <ranges> 8 #include <string> 9 #include <vector> 10 11 namespace redfish::registries 12 { 13 14 const Message* getMessageFromRegistry(const std::string& messageKey, 15 std::span<const MessageEntry> registry) 16 { 17 std::span<const MessageEntry>::iterator messageIt = std::ranges::find_if( 18 registry, [&messageKey](const MessageEntry& messageEntry) { 19 return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 20 }); 21 if (messageIt != registry.end()) 22 { 23 return &messageIt->second; 24 } 25 26 return nullptr; 27 } 28 29 const Message* getMessage(std::string_view messageID) 30 { 31 // Redfish MessageIds are in the form 32 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 33 // the right Message 34 std::vector<std::string> fields; 35 fields.reserve(4); 36 bmcweb::split(fields, messageID, '.'); 37 const std::string& registryName = fields[0]; 38 const std::string& messageKey = fields[3]; 39 40 // Find the right registry and check it for the MessageKey 41 if (std::string(base::header.registryPrefix) == registryName) 42 { 43 return getMessageFromRegistry( 44 messageKey, std::span<const MessageEntry>(base::registry)); 45 } 46 if (std::string(openbmc::header.registryPrefix) == registryName) 47 { 48 return getMessageFromRegistry( 49 messageKey, std::span<const MessageEntry>(openbmc::registry)); 50 } 51 return nullptr; 52 } 53 54 } // namespace redfish::registries 55