1 #include "processing.hpp" 2 3 #include <boost/algorithm/string/predicate.hpp> 4 5 bool getWellKnown( 6 const boost::container::flat_map<std::string, std::string>& owners, 7 const std::string& request, std::string& wellKnown) 8 { 9 // If it's already a well known name, just return 10 if (!boost::starts_with(request, ":")) 11 { 12 wellKnown = request; 13 return true; 14 } 15 16 auto it = owners.find(request); 17 if (it == owners.end()) 18 { 19 return false; 20 } 21 wellKnown = it->second; 22 return true; 23 } 24 25 bool needToIntrospect(const std::string& processName, 26 const WhiteBlackList& whiteList, 27 const WhiteBlackList& blackList) 28 { 29 auto inWhitelist = 30 std::find_if(whiteList.begin(), whiteList.end(), 31 [&processName](const auto& prefix) { 32 return boost::starts_with(processName, prefix); 33 }) != whiteList.end(); 34 35 // This holds full service names, not prefixes 36 auto inBlacklist = blackList.find(processName) != blackList.end(); 37 38 return inWhitelist && !inBlacklist; 39 } 40 41 void processNameChangeDelete( 42 boost::container::flat_map<std::string, std::string>& nameOwners, 43 const std::string& wellKnown, const std::string& oldOwner, 44 interface_map_type& interfaceMap, AssociationOwnersType& assocOwners, 45 AssociationInterfaces& assocInterfaces, 46 sdbusplus::asio::object_server& server) 47 { 48 if (boost::starts_with(oldOwner, ":")) 49 { 50 auto it = nameOwners.find(oldOwner); 51 if (it != nameOwners.end()) 52 { 53 nameOwners.erase(it); 54 } 55 } 56 // Connection removed 57 interface_map_type::iterator pathIt = interfaceMap.begin(); 58 while (pathIt != interfaceMap.end()) 59 { 60 // If an associations interface is being removed, 61 // also need to remove the corresponding associations 62 // objects and properties. 63 auto ifaces = pathIt->second.find(wellKnown); 64 if (ifaces != pathIt->second.end()) 65 { 66 auto assoc = std::find(ifaces->second.begin(), ifaces->second.end(), 67 ASSOCIATIONS_INTERFACE); 68 if (assoc != ifaces->second.end()) 69 { 70 removeAssociation(pathIt->first, wellKnown, server, assocOwners, 71 assocInterfaces); 72 } 73 } 74 pathIt->second.erase(wellKnown); 75 if (pathIt->second.empty()) 76 { 77 // If the last connection to the object is gone, 78 // delete the top level object 79 pathIt = interfaceMap.erase(pathIt); 80 continue; 81 } 82 pathIt++; 83 } 84 } 85