From c5fba0cd2c1dcac7c4da144770ff0539226c94b1 Mon Sep 17 00:00:00 2001 From: Nivi Sarkar <55898241+nivi-apple@users.noreply.github.com> Date: Fri, 29 Mar 2024 10:42:21 -0700 Subject: [PATCH] Add domain names matching the DnssdServices stored in Browse Context (#32740) * Add domain names matching the DnssdServices stored in Browse Context This is needed to pass the domain returned from a call to Browse to the Resolve. * Restyled by clang-format * Add the domain names to the services vector * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/platform/Darwin/DnssdContexts.cpp | 16 +++++++++++----- src/platform/Darwin/DnssdImpl.h | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index f1335641d67dbf..06b6e024c3f19f 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -368,7 +368,12 @@ void BrowseContext::DispatchSuccess() void BrowseContext::DispatchPartialSuccess() { sContextDispatchingSuccess = this; - callback(context, services.data(), services.size(), false, CHIP_NO_ERROR); + std::vector dnsServices; + for (auto iter : services) + { + dnsServices.push_back(std::move(iter.first)); + } + callback(context, dnsServices.data(), dnsServices.size(), false, CHIP_NO_ERROR); sContextDispatchingSuccess = nullptr; services.clear(); } @@ -390,7 +395,7 @@ void BrowseContext::OnBrowseAdd(const char * name, const char * type, const char VerifyOrReturn(IsLocalDomain(domain)); auto service = GetService(name, type, protocol, interfaceId); - services.push_back(service); + services.push_back(std::make_pair(std::move(service), std::string(domain))); } void BrowseContext::OnBrowseRemove(const char * name, const char * type, const char * domain, uint32_t interfaceId) @@ -402,9 +407,10 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c VerifyOrReturn(IsLocalDomain(domain)); services.erase(std::remove_if(services.begin(), services.end(), - [name, type, interfaceId](const DnssdService & service) { - return strcmp(name, service.mName) == 0 && type == GetFullType(&service) && - service.mInterface == chip::Inet::InterfaceId(interfaceId); + [name, type, interfaceId, domain](const auto & service) { + return strcmp(name, service.first.mName) == 0 && type == GetFullType(&service.first) && + service.first.mInterface == chip::Inet::InterfaceId(interfaceId) && + strcmp(domain, service.second.c_str()) == 0; }), services.end()); } diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index 18f1d93baaab27..f09518025c493f 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -167,7 +167,7 @@ struct BrowseHandler : public GenericContext struct BrowseContext : public BrowseHandler { DnssdBrowseCallback callback; - std::vector services; + std::vector> services; BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol);