Skip to content

Commit 1001114

Browse files
vivien-applepull[bot]
authored andcommitted
[Darwin] Pass the correct type to the register callback (#17767)
1 parent 0c7243c commit 1001114

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/platform/Darwin/DnssdContexts.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ std::string GetHostNameWithoutDomain(const char * hostnameWithDomain)
3939
return hostname;
4040
}
4141

42+
std::string GetFullTypeWithoutSubTypes(std::string fullType)
43+
{
44+
size_t position = fullType.find(",");
45+
if (position != std::string::npos)
46+
{
47+
fullType.erase(position);
48+
}
49+
50+
return fullType;
51+
}
52+
4253
void GetTextEntries(DnssdService & service, const unsigned char * data, uint16_t len)
4354
{
4455
uint16_t recordCount = TXTRecordGetCount(len, data);
@@ -246,7 +257,7 @@ RegisterContext::RegisterContext(const char * sType, DnssdPublishCallback cb, vo
246257
context = cbContext;
247258
callback = cb;
248259

249-
Platform::CopyString(mType, sType);
260+
mType = sType;
250261
}
251262

252263
void RegisterContext::DispatchFailure(DNSServiceErrorType err)
@@ -258,7 +269,8 @@ void RegisterContext::DispatchFailure(DNSServiceErrorType err)
258269

259270
void RegisterContext::DispatchSuccess()
260271
{
261-
callback(context, mType, CHIP_NO_ERROR);
272+
std::string typeWithoutSubTypes = GetFullTypeWithoutSubTypes(mType);
273+
callback(context, typeWithoutSubTypes.c_str(), CHIP_NO_ERROR);
262274
}
263275

264276
BrowseContext::BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol)

src/platform/Darwin/DnssdImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ class MdnsContexts
9191
struct RegisterContext : public GenericContext
9292
{
9393
DnssdPublishCallback callback;
94-
char mType[kDnssdTypeMaxSize + 1];
94+
std::string mType;
9595

9696
RegisterContext(const char * sType, DnssdPublishCallback cb, void * cbContext);
9797
virtual ~RegisterContext() {}
9898

9999
void DispatchFailure(DNSServiceErrorType err) override;
100100
void DispatchSuccess() override;
101101

102-
bool matches(const char * sType) { return (strcmp(mType, sType) == 0); }
102+
bool matches(const char * sType) { return mType.compare(sType) == 0; }
103103
};
104104

105105
struct BrowseContext : public GenericContext

0 commit comments

Comments
 (0)