From 3ed535f04524fd6f28cf1244fcf8553cacaad382 Mon Sep 17 00:00:00 2001 From: Nivedita Sarkar Date: Tue, 26 Mar 2024 14:39:35 -0700 Subject: [PATCH 1/4] 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. --- src/platform/Darwin/DnssdContexts.cpp | 9 +++++++++ src/platform/Darwin/DnssdImpl.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index f1335641d67dbf..59a09736ff46b5 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -371,6 +371,7 @@ void BrowseContext::DispatchPartialSuccess() callback(context, services.data(), services.size(), false, CHIP_NO_ERROR); sContextDispatchingSuccess = nullptr; services.clear(); + domainNames.clear(); } void BrowseContext::OnBrowse(DNSServiceFlags flags, const char * name, const char * type, const char * domain, uint32_t interfaceId) @@ -391,6 +392,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); + domainNames.push_back(std::make_pair(service, std::string(domain))); } void BrowseContext::OnBrowseRemove(const char * name, const char * type, const char * domain, uint32_t interfaceId) @@ -401,6 +403,13 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c VerifyOrReturn(name != nullptr); VerifyOrReturn(IsLocalDomain(domain)); + domainNames.erase(std::remove_if(domainNames.begin(), domainNames.end(), + [name, type, interfaceId](const auto & domainName) { + return strcmp(domainName.first.mName, name) == 0 && domainName.first.mType == type && + domainName.first.mInterface == chip::Inet::InterfaceId(interfaceId); + }), + domainNames.end()); + services.erase(std::remove_if(services.begin(), services.end(), [name, type, interfaceId](const DnssdService & service) { return strcmp(name, service.mName) == 0 && type == GetFullType(&service) && diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index 18f1d93baaab27..12a25da5d2f758 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -168,6 +168,7 @@ struct BrowseContext : public BrowseHandler { DnssdBrowseCallback callback; std::vector services; + std::vector> domainNames; BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol); From 0fda155a0e87c7333dbdffa60ccd40f028786dd9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 26 Mar 2024 23:08:51 +0000 Subject: [PATCH 2/4] Restyled by clang-format --- src/platform/Darwin/DnssdContexts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index 59a09736ff46b5..74d8197ddf7067 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -406,7 +406,7 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c domainNames.erase(std::remove_if(domainNames.begin(), domainNames.end(), [name, type, interfaceId](const auto & domainName) { return strcmp(domainName.first.mName, name) == 0 && domainName.first.mType == type && - domainName.first.mInterface == chip::Inet::InterfaceId(interfaceId); + domainName.first.mInterface == chip::Inet::InterfaceId(interfaceId); }), domainNames.end()); From 009055c94b9a01809bf63542ecd4596a6be176f0 Mon Sep 17 00:00:00 2001 From: Nivedita Sarkar Date: Thu, 28 Mar 2024 14:56:19 -0700 Subject: [PATCH 3/4] Add the domain names to the services vector --- src/platform/Darwin/DnssdContexts.cpp | 24 ++++++++++-------------- src/platform/Darwin/DnssdImpl.h | 3 +-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index 74d8197ddf7067..e80341d2508ffb 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -368,10 +368,14 @@ 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(); - domainNames.clear(); } void BrowseContext::OnBrowse(DNSServiceFlags flags, const char * name, const char * type, const char * domain, uint32_t interfaceId) @@ -391,8 +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); - domainNames.push_back(std::make_pair(service, std::string(domain))); + 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) @@ -403,17 +406,10 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c VerifyOrReturn(name != nullptr); VerifyOrReturn(IsLocalDomain(domain)); - domainNames.erase(std::remove_if(domainNames.begin(), domainNames.end(), - [name, type, interfaceId](const auto & domainName) { - return strcmp(domainName.first.mName, name) == 0 && domainName.first.mType == type && - domainName.first.mInterface == chip::Inet::InterfaceId(interfaceId); - }), - domainNames.end()); - 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 12a25da5d2f758..f09518025c493f 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -167,8 +167,7 @@ struct BrowseHandler : public GenericContext struct BrowseContext : public BrowseHandler { DnssdBrowseCallback callback; - std::vector services; - std::vector> domainNames; + std::vector> services; BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol); From dec1f9a47856edac17ca1ebae6b3ad493f699c23 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 28 Mar 2024 21:57:01 +0000 Subject: [PATCH 4/4] Restyled by clang-format --- src/platform/Darwin/DnssdContexts.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index e80341d2508ffb..06b6e024c3f19f 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -409,7 +409,8 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c services.erase(std::remove_if(services.begin(), services.end(), [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; + service.first.mInterface == chip::Inet::InterfaceId(interfaceId) && + strcmp(domain, service.second.c_str()) == 0; }), services.end()); }