1 #include "associations.hpp" 2 #include "processing.hpp" 3 #include "src/argument.hpp" 4 #include "types.hpp" 5 6 #include <tinyxml2.h> 7 8 #include <atomic> 9 #include <boost/algorithm/string/case_conv.hpp> 10 #include <boost/algorithm/string/predicate.hpp> 11 #include <boost/container/flat_map.hpp> 12 #include <chrono> 13 #include <iomanip> 14 #include <iostream> 15 #include <sdbusplus/asio/connection.hpp> 16 #include <sdbusplus/asio/object_server.hpp> 17 18 constexpr const char* OBJECT_MAPPER_DBUS_NAME = 19 "xyz.openbmc_project.ObjectMapper"; 20 21 AssociationInterfaces associationInterfaces; 22 AssociationOwnersType associationOwners; 23 24 static WhiteBlackList service_whitelist; 25 static WhiteBlackList service_blacklist; 26 27 /** Exception thrown when a path is not found in the object list. */ 28 struct NotFoundException final : public sdbusplus::exception_t 29 { 30 const char* name() const noexcept override 31 { 32 return "org.freedesktop.DBus.Error.FileNotFound"; 33 }; 34 const char* description() const noexcept override 35 { 36 return "path or object not found"; 37 }; 38 const char* what() const noexcept override 39 { 40 return "org.freedesktop.DBus.Error.FileNotFound: " 41 "The requested object was not found"; 42 }; 43 }; 44 45 void update_owners(sdbusplus::asio::connection* conn, 46 boost::container::flat_map<std::string, std::string>& owners, 47 const std::string& new_object) 48 { 49 if (boost::starts_with(new_object, ":")) 50 { 51 return; 52 } 53 conn->async_method_call( 54 [&, new_object](const boost::system::error_code ec, 55 const std::string& nameOwner) { 56 if (ec) 57 { 58 std::cerr << "Error getting owner of " << new_object << " : " 59 << ec << "\n"; 60 return; 61 } 62 owners[nameOwner] = new_object; 63 }, 64 "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetNameOwner", 65 new_object); 66 } 67 68 void send_introspection_complete_signal(sdbusplus::asio::connection* system_bus, 69 const std::string& process_name) 70 { 71 // TODO(ed) This signal doesn't get exposed properly in the 72 // introspect right now. Find out how to register signals in 73 // sdbusplus 74 sdbusplus::message::message m = system_bus->new_signal( 75 "/xyz/openbmc_project/object_mapper", 76 "xyz.openbmc_project.ObjectMapper.Private", "IntrospectionComplete"); 77 m.append(process_name); 78 m.signal_send(); 79 } 80 81 struct InProgressIntrospect 82 { 83 InProgressIntrospect( 84 sdbusplus::asio::connection* system_bus, boost::asio::io_service& io, 85 const std::string& process_name 86 #ifdef DEBUG 87 , 88 std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> 89 global_start_time 90 #endif 91 ) : 92 system_bus(system_bus), 93 io(io), process_name(process_name) 94 #ifdef DEBUG 95 , 96 global_start_time(global_start_time), 97 process_start_time(std::chrono::steady_clock::now()) 98 #endif 99 { 100 } 101 ~InProgressIntrospect() 102 { 103 send_introspection_complete_signal(system_bus, process_name); 104 105 #ifdef DEBUG 106 std::chrono::duration<float> diff = 107 std::chrono::steady_clock::now() - process_start_time; 108 std::cout << std::setw(50) << process_name << " scan took " 109 << diff.count() << " seconds\n"; 110 111 // If we're the last outstanding caller globally, calculate the 112 // time it took 113 if (global_start_time != nullptr && global_start_time.use_count() == 1) 114 { 115 diff = std::chrono::steady_clock::now() - *global_start_time; 116 std::cout << "Total scan took " << diff.count() 117 << " seconds to complete\n"; 118 } 119 #endif 120 } 121 sdbusplus::asio::connection* system_bus; 122 boost::asio::io_service& io; 123 std::string process_name; 124 #ifdef DEBUG 125 std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> 126 global_start_time; 127 std::chrono::time_point<std::chrono::steady_clock> process_start_time; 128 #endif 129 }; 130 131 void do_associations(sdbusplus::asio::connection* system_bus, 132 sdbusplus::asio::object_server& objectServer, 133 const std::string& processName, const std::string& path, 134 const std::string& assocDefIface) 135 { 136 system_bus->async_method_call( 137 [&objectServer, path, processName]( 138 const boost::system::error_code ec, 139 const sdbusplus::message::variant<std::vector<Association>>& 140 variantAssociations) { 141 if (ec) 142 { 143 std::cerr << "Error getting associations from " << path << "\n"; 144 } 145 std::vector<Association> associations = 146 sdbusplus::message::variant_ns::get<std::vector<Association>>( 147 variantAssociations); 148 associationChanged(objectServer, associations, path, processName, 149 associationOwners, associationInterfaces); 150 }, 151 processName, path, "org.freedesktop.DBus.Properties", "Get", 152 assocDefIface, getAssocDefPropName(assocDefIface)); 153 } 154 155 void do_introspect(sdbusplus::asio::connection* system_bus, 156 std::shared_ptr<InProgressIntrospect> transaction, 157 interface_map_type& interface_map, 158 sdbusplus::asio::object_server& objectServer, 159 std::string path) 160 { 161 system_bus->async_method_call( 162 [&interface_map, &objectServer, transaction, path, 163 system_bus](const boost::system::error_code ec, 164 const std::string& introspect_xml) { 165 if (ec) 166 { 167 std::cerr << "Introspect call failed with error: " << ec << ", " 168 << ec.message() 169 << " on process: " << transaction->process_name 170 << " path: " << path << "\n"; 171 return; 172 } 173 174 tinyxml2::XMLDocument doc; 175 176 tinyxml2::XMLError e = doc.Parse(introspect_xml.c_str()); 177 if (e != tinyxml2::XMLError::XML_SUCCESS) 178 { 179 std::cerr << "XML parsing failed\n"; 180 return; 181 } 182 183 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); 184 if (pRoot == nullptr) 185 { 186 std::cerr << "XML document did not contain any data\n"; 187 return; 188 } 189 auto& thisPathMap = interface_map[path]; 190 tinyxml2::XMLElement* pElement = 191 pRoot->FirstChildElement("interface"); 192 while (pElement != nullptr) 193 { 194 const char* iface_name = pElement->Attribute("name"); 195 if (iface_name == nullptr) 196 { 197 continue; 198 } 199 200 thisPathMap[transaction->process_name].emplace(iface_name); 201 202 if (isAssocDefIface(iface_name)) 203 { 204 do_associations(system_bus, objectServer, 205 transaction->process_name, path, 206 iface_name); 207 } 208 209 pElement = pElement->NextSiblingElement("interface"); 210 } 211 212 pElement = pRoot->FirstChildElement("node"); 213 while (pElement != nullptr) 214 { 215 const char* child_path = pElement->Attribute("name"); 216 if (child_path != nullptr) 217 { 218 std::string parent_path(path); 219 if (parent_path == "/") 220 { 221 parent_path.clear(); 222 } 223 224 do_introspect(system_bus, transaction, interface_map, 225 objectServer, parent_path + "/" + child_path); 226 } 227 pElement = pElement->NextSiblingElement("node"); 228 } 229 }, 230 transaction->process_name, path, "org.freedesktop.DBus.Introspectable", 231 "Introspect"); 232 } 233 234 void start_new_introspect( 235 sdbusplus::asio::connection* system_bus, boost::asio::io_service& io, 236 interface_map_type& interface_map, const std::string& process_name, 237 #ifdef DEBUG 238 std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> 239 global_start_time, 240 #endif 241 sdbusplus::asio::object_server& objectServer) 242 { 243 if (needToIntrospect(process_name, service_whitelist, service_blacklist)) 244 { 245 std::shared_ptr<InProgressIntrospect> transaction = 246 std::make_shared<InProgressIntrospect>(system_bus, io, process_name 247 #ifdef DEBUG 248 , 249 global_start_time 250 #endif 251 ); 252 253 do_introspect(system_bus, transaction, interface_map, objectServer, 254 "/"); 255 } 256 } 257 258 // TODO(ed) replace with std::set_intersection once c++17 is available 259 template <class InputIt1, class InputIt2> 260 bool intersect(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) 261 { 262 while (first1 != last1 && first2 != last2) 263 { 264 if (*first1 < *first2) 265 { 266 ++first1; 267 continue; 268 } 269 if (*first2 < *first1) 270 { 271 ++first2; 272 continue; 273 } 274 return true; 275 } 276 return false; 277 } 278 279 void doListNames( 280 boost::asio::io_service& io, interface_map_type& interface_map, 281 sdbusplus::asio::connection* system_bus, 282 boost::container::flat_map<std::string, std::string>& name_owners, 283 sdbusplus::asio::object_server& objectServer) 284 { 285 system_bus->async_method_call( 286 [&io, &interface_map, &name_owners, &objectServer, 287 system_bus](const boost::system::error_code ec, 288 std::vector<std::string> process_names) { 289 if (ec) 290 { 291 std::cerr << "Error getting names: " << ec << "\n"; 292 std::exit(EXIT_FAILURE); 293 return; 294 } 295 // Try to make startup consistent 296 std::sort(process_names.begin(), process_names.end()); 297 #ifdef DEBUG 298 std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> 299 global_start_time = std::make_shared< 300 std::chrono::time_point<std::chrono::steady_clock>>( 301 std::chrono::steady_clock::now()); 302 #endif 303 for (const std::string& process_name : process_names) 304 { 305 if (needToIntrospect(process_name, service_whitelist, 306 service_blacklist)) 307 { 308 start_new_introspect(system_bus, io, interface_map, 309 process_name, 310 #ifdef DEBUG 311 global_start_time, 312 #endif 313 objectServer); 314 update_owners(system_bus, name_owners, process_name); 315 } 316 } 317 }, 318 "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", 319 "ListNames"); 320 } 321 322 void splitArgs(const std::string& stringArgs, 323 boost::container::flat_set<std::string>& listArgs) 324 { 325 std::istringstream args; 326 std::string arg; 327 328 args.str(stringArgs); 329 330 while (!args.eof()) 331 { 332 args >> arg; 333 if (!arg.empty()) 334 { 335 listArgs.insert(arg); 336 } 337 } 338 } 339 340 void addObjectMapResult( 341 std::vector<interface_map_type::value_type>& objectMap, 342 const std::string& objectPath, 343 const std::pair<std::string, boost::container::flat_set<std::string>>& 344 interfaceMap) 345 { 346 // Adds an object path/service name/interface list entry to 347 // the results of GetSubTree and GetAncestors. 348 // If an entry for the object path already exists, just add the 349 // service name and interfaces to that entry, otherwise create 350 // a new entry. 351 auto entry = std::find_if( 352 objectMap.begin(), objectMap.end(), 353 [&objectPath](const auto& i) { return objectPath == i.first; }); 354 355 if (entry != objectMap.end()) 356 { 357 entry->second.emplace(interfaceMap); 358 } 359 else 360 { 361 interface_map_type::value_type object; 362 object.first = objectPath; 363 object.second.emplace(interfaceMap); 364 objectMap.push_back(object); 365 } 366 } 367 368 // Remove parents of the passed in path that: 369 // 1) Only have the 3 default interfaces on them 370 // - Means D-Bus created these, not application code, 371 // with the Properties, Introspectable, and Peer ifaces 372 // 2) Have no other child for this owner 373 void removeUnneededParents(const std::string& objectPath, 374 const std::string& owner, 375 interface_map_type& interface_map) 376 { 377 auto parent = objectPath; 378 379 while (true) 380 { 381 auto pos = parent.find_last_of('/'); 382 if ((pos == std::string::npos) || (pos == 0)) 383 { 384 break; 385 } 386 parent = parent.substr(0, pos); 387 388 auto parent_it = interface_map.find(parent); 389 if (parent_it == interface_map.end()) 390 { 391 break; 392 } 393 394 auto ifaces_it = parent_it->second.find(owner); 395 if (ifaces_it == parent_it->second.end()) 396 { 397 break; 398 } 399 400 if (ifaces_it->second.size() != 3) 401 { 402 break; 403 } 404 405 auto child_path = parent + '/'; 406 407 // Remove this parent if there isn't a remaining child on this owner 408 auto child = std::find_if( 409 interface_map.begin(), interface_map.end(), 410 [&owner, &child_path](const auto& entry) { 411 return boost::starts_with(entry.first, child_path) && 412 (entry.second.find(owner) != entry.second.end()); 413 }); 414 415 if (child == interface_map.end()) 416 { 417 parent_it->second.erase(ifaces_it); 418 if (parent_it->second.empty()) 419 { 420 interface_map.erase(parent_it); 421 } 422 } 423 else 424 { 425 break; 426 } 427 } 428 } 429 430 int main(int argc, char** argv) 431 { 432 auto options = ArgumentParser(argc, argv); 433 boost::asio::io_service io; 434 std::shared_ptr<sdbusplus::asio::connection> system_bus = 435 std::make_shared<sdbusplus::asio::connection>(io); 436 437 splitArgs(options["service-namespaces"], service_whitelist); 438 splitArgs(options["service-blacklists"], service_blacklist); 439 440 // TODO(Ed) Remove this once all service files are updated to not use this. 441 // For now, simply squash the input, and ignore it. 442 boost::container::flat_set<std::string> iface_whitelist; 443 splitArgs(options["interface-namespaces"], iface_whitelist); 444 445 system_bus->request_name(OBJECT_MAPPER_DBUS_NAME); 446 sdbusplus::asio::object_server server(system_bus); 447 448 // Construct a signal set registered for process termination. 449 boost::asio::signal_set signals(io, SIGINT, SIGTERM); 450 signals.async_wait([&io](const boost::system::error_code& error, 451 int signal_number) { io.stop(); }); 452 453 interface_map_type interface_map; 454 boost::container::flat_map<std::string, std::string> name_owners; 455 456 std::function<void(sdbusplus::message::message & message)> 457 nameChangeHandler = [&interface_map, &io, &name_owners, &server, 458 system_bus](sdbusplus::message::message& message) { 459 std::string name; // well-known 460 std::string old_owner; // unique-name 461 std::string new_owner; // unique-name 462 463 message.read(name, old_owner, new_owner); 464 465 if (!old_owner.empty()) 466 { 467 processNameChangeDelete(name_owners, name, old_owner, 468 interface_map, associationOwners, 469 associationInterfaces, server); 470 } 471 472 if (!new_owner.empty()) 473 { 474 #ifdef DEBUG 475 auto transaction = std::make_shared< 476 std::chrono::time_point<std::chrono::steady_clock>>( 477 std::chrono::steady_clock::now()); 478 #endif 479 // New daemon added 480 if (needToIntrospect(name, service_whitelist, 481 service_blacklist)) 482 { 483 name_owners[new_owner] = name; 484 start_new_introspect(system_bus.get(), io, interface_map, 485 name, 486 #ifdef DEBUG 487 transaction, 488 #endif 489 server); 490 } 491 } 492 }; 493 494 sdbusplus::bus::match::match nameOwnerChanged( 495 static_cast<sdbusplus::bus::bus&>(*system_bus), 496 sdbusplus::bus::match::rules::nameOwnerChanged(), nameChangeHandler); 497 498 std::function<void(sdbusplus::message::message & message)> 499 interfacesAddedHandler = [&interface_map, &name_owners, &server]( 500 sdbusplus::message::message& message) { 501 sdbusplus::message::object_path obj_path; 502 InterfacesAdded interfaces_added; 503 message.read(obj_path, interfaces_added); 504 std::string well_known; 505 if (!getWellKnown(name_owners, message.get_sender(), well_known)) 506 { 507 return; // only introspect well-known 508 } 509 if (needToIntrospect(well_known, service_whitelist, 510 service_blacklist)) 511 { 512 processInterfaceAdded(interface_map, obj_path, interfaces_added, 513 well_known, associationOwners, 514 associationInterfaces, server); 515 } 516 }; 517 518 sdbusplus::bus::match::match interfacesAdded( 519 static_cast<sdbusplus::bus::bus&>(*system_bus), 520 sdbusplus::bus::match::rules::interfacesAdded(), 521 interfacesAddedHandler); 522 523 std::function<void(sdbusplus::message::message & message)> 524 interfacesRemovedHandler = [&interface_map, &name_owners, &server]( 525 sdbusplus::message::message& message) { 526 sdbusplus::message::object_path obj_path; 527 std::vector<std::string> interfaces_removed; 528 message.read(obj_path, interfaces_removed); 529 auto connection_map = interface_map.find(obj_path.str); 530 if (connection_map == interface_map.end()) 531 { 532 return; 533 } 534 535 std::string sender; 536 if (!getWellKnown(name_owners, message.get_sender(), sender)) 537 { 538 return; 539 } 540 for (const std::string& interface : interfaces_removed) 541 { 542 auto interface_set = connection_map->second.find(sender); 543 if (interface_set == connection_map->second.end()) 544 { 545 continue; 546 } 547 548 if (isAssocDefIface(interface)) 549 { 550 removeAssociation(obj_path.str, sender, server, 551 associationOwners, associationInterfaces); 552 } 553 554 interface_set->second.erase(interface); 555 // If this was the last interface on this connection, 556 // erase the connection 557 if (interface_set->second.empty()) 558 { 559 connection_map->second.erase(interface_set); 560 } 561 } 562 // If this was the last connection on this object path, 563 // erase the object path 564 if (connection_map->second.empty()) 565 { 566 interface_map.erase(connection_map); 567 } 568 569 removeUnneededParents(obj_path.str, sender, interface_map); 570 }; 571 572 sdbusplus::bus::match::match interfacesRemoved( 573 static_cast<sdbusplus::bus::bus&>(*system_bus), 574 sdbusplus::bus::match::rules::interfacesRemoved(), 575 interfacesRemovedHandler); 576 577 std::function<void(sdbusplus::message::message & message)> 578 associationChangedHandler = [&server, &name_owners]( 579 sdbusplus::message::message& message) { 580 std::string objectName; 581 boost::container::flat_map< 582 std::string, 583 sdbusplus::message::variant<std::vector<Association>>> 584 values; 585 message.read(objectName, values); 586 587 auto prop = 588 std::find_if(values.begin(), values.end(), [](const auto& v) { 589 using namespace boost::algorithm; 590 return to_lower_copy(v.first) == "associations"; 591 }); 592 593 if (prop != values.end()) 594 { 595 std::vector<Association> associations = 596 sdbusplus::message::variant_ns::get< 597 std::vector<Association>>(prop->second); 598 599 std::string well_known; 600 if (!getWellKnown(name_owners, message.get_sender(), 601 well_known)) 602 { 603 return; 604 } 605 associationChanged(server, associations, message.get_path(), 606 well_known, associationOwners, 607 associationInterfaces); 608 } 609 }; 610 sdbusplus::bus::match::match assocChangedMatch( 611 static_cast<sdbusplus::bus::bus&>(*system_bus), 612 sdbusplus::bus::match::rules::interface( 613 "org.freedesktop.DBus.Properties") + 614 sdbusplus::bus::match::rules::member("PropertiesChanged") + 615 sdbusplus::bus::match::rules::argN(0, assocDefsInterface), 616 associationChangedHandler); 617 618 sdbusplus::bus::match::match orgOpenbmcAssocChangedMatch( 619 static_cast<sdbusplus::bus::bus&>(*system_bus), 620 sdbusplus::bus::match::rules::interface( 621 "org.freedesktop.DBus.Properties") + 622 sdbusplus::bus::match::rules::member("PropertiesChanged") + 623 sdbusplus::bus::match::rules::argN(0, orgOpenBMCAssocDefsInterface), 624 associationChangedHandler); 625 626 std::shared_ptr<sdbusplus::asio::dbus_interface> iface = 627 server.add_interface("/xyz/openbmc_project/object_mapper", 628 "xyz.openbmc_project.ObjectMapper"); 629 630 iface->register_method( 631 "GetAncestors", [&interface_map](std::string& req_path, 632 std::vector<std::string>& interfaces) { 633 // Interfaces need to be sorted for intersect to function 634 std::sort(interfaces.begin(), interfaces.end()); 635 636 if (boost::ends_with(req_path, "/")) 637 { 638 req_path.pop_back(); 639 } 640 if (req_path.size() && 641 interface_map.find(req_path) == interface_map.end()) 642 { 643 throw NotFoundException(); 644 } 645 646 std::vector<interface_map_type::value_type> ret; 647 for (auto& object_path : interface_map) 648 { 649 auto& this_path = object_path.first; 650 if (boost::starts_with(req_path, this_path) && 651 (req_path != this_path)) 652 { 653 if (interfaces.empty()) 654 { 655 ret.emplace_back(object_path); 656 } 657 else 658 { 659 for (auto& interface_map : object_path.second) 660 { 661 662 if (intersect(interfaces.begin(), interfaces.end(), 663 interface_map.second.begin(), 664 interface_map.second.end())) 665 { 666 addObjectMapResult(ret, this_path, 667 interface_map); 668 } 669 } 670 } 671 } 672 } 673 674 return ret; 675 }); 676 677 iface->register_method( 678 "GetObject", [&interface_map](const std::string& path, 679 std::vector<std::string>& interfaces) { 680 boost::container::flat_map<std::string, 681 boost::container::flat_set<std::string>> 682 results; 683 684 // Interfaces need to be sorted for intersect to function 685 std::sort(interfaces.begin(), interfaces.end()); 686 auto path_ref = interface_map.find(path); 687 if (path_ref == interface_map.end()) 688 { 689 throw NotFoundException(); 690 } 691 if (interfaces.empty()) 692 { 693 return path_ref->second; 694 } 695 for (auto& interface_map : path_ref->second) 696 { 697 if (intersect(interfaces.begin(), interfaces.end(), 698 interface_map.second.begin(), 699 interface_map.second.end())) 700 { 701 results.emplace(interface_map.first, interface_map.second); 702 } 703 } 704 705 if (results.empty()) 706 { 707 throw NotFoundException(); 708 } 709 710 return results; 711 }); 712 713 iface->register_method( 714 "GetSubTree", [&interface_map](std::string& req_path, int32_t depth, 715 std::vector<std::string>& interfaces) { 716 if (depth <= 0) 717 { 718 depth = std::numeric_limits<int32_t>::max(); 719 } 720 // Interfaces need to be sorted for intersect to function 721 std::sort(interfaces.begin(), interfaces.end()); 722 std::vector<interface_map_type::value_type> ret; 723 724 if (boost::ends_with(req_path, "/")) 725 { 726 req_path.pop_back(); 727 } 728 if (req_path.size() && 729 interface_map.find(req_path) == interface_map.end()) 730 { 731 throw NotFoundException(); 732 } 733 734 for (auto& object_path : interface_map) 735 { 736 auto& this_path = object_path.first; 737 738 if (this_path == req_path) 739 { 740 continue; 741 } 742 743 if (boost::starts_with(this_path, req_path)) 744 { 745 // count the number of slashes past the search term 746 int32_t this_depth = 747 std::count(this_path.begin() + req_path.size(), 748 this_path.end(), '/'); 749 if (this_depth <= depth) 750 { 751 for (auto& interface_map : object_path.second) 752 { 753 if (intersect(interfaces.begin(), interfaces.end(), 754 interface_map.second.begin(), 755 interface_map.second.end()) || 756 interfaces.empty()) 757 { 758 addObjectMapResult(ret, this_path, 759 interface_map); 760 } 761 } 762 } 763 } 764 } 765 766 return ret; 767 }); 768 769 iface->register_method( 770 "GetSubTreePaths", 771 [&interface_map](std::string& req_path, int32_t depth, 772 std::vector<std::string>& interfaces) { 773 if (depth <= 0) 774 { 775 depth = std::numeric_limits<int32_t>::max(); 776 } 777 // Interfaces need to be sorted for intersect to function 778 std::sort(interfaces.begin(), interfaces.end()); 779 std::vector<std::string> ret; 780 781 if (boost::ends_with(req_path, "/")) 782 { 783 req_path.pop_back(); 784 } 785 if (req_path.size() && 786 interface_map.find(req_path) == interface_map.end()) 787 { 788 throw NotFoundException(); 789 } 790 791 for (auto& object_path : interface_map) 792 { 793 auto& this_path = object_path.first; 794 795 if (this_path == req_path) 796 { 797 continue; 798 } 799 800 if (boost::starts_with(this_path, req_path)) 801 { 802 // count the number of slashes past the search term 803 int this_depth = 804 std::count(this_path.begin() + req_path.size(), 805 this_path.end(), '/'); 806 if (this_depth <= depth) 807 { 808 bool add = interfaces.empty(); 809 for (auto& interface_map : object_path.second) 810 { 811 if (intersect(interfaces.begin(), interfaces.end(), 812 interface_map.second.begin(), 813 interface_map.second.end())) 814 { 815 add = true; 816 break; 817 } 818 } 819 if (add) 820 { 821 // TODO(ed) this is a copy 822 ret.emplace_back(this_path); 823 } 824 } 825 } 826 } 827 828 return ret; 829 }); 830 831 iface->initialize(); 832 833 io.post([&]() { 834 doListNames(io, interface_map, system_bus.get(), name_owners, server); 835 }); 836 837 io.run(); 838 } 839