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