Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
superwhd committed Feb 17, 2025
1 parent e2f3c1f commit f2a897e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/mdns/mdns_mdnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ otbrError PublisherMDnsSd::DnssdServiceRegistration::Register(void)
DnssdKeyRegistration *keyReg;
DNSServiceErrorType dnsError;

VerifyOrExit(GetPublisher().IsStarted(), dnsError = kDNSServiceErr_ServiceNotRunning);

if (!mHostName.empty())
{
fullHostName = MakeFullHostName(mHostName);
Expand Down Expand Up @@ -484,13 +486,15 @@ otbrError PublisherMDnsSd::DnssdServiceRegistration::Register(void)
keyReg->Register();
}

exit:
return GetPublisher().DnsErrorToOtbrError(dnsError);
}

void PublisherMDnsSd::DnssdServiceRegistration::Unregister(void)
{
DnssdKeyRegistration *keyReg = mRelatedKeyReg;

VerifyOrExit(GetPublisher().IsStarted());
VerifyOrExit(mServiceRef != nullptr);

// If we have a related key registration associated with this
Expand Down Expand Up @@ -560,6 +564,8 @@ otbrError PublisherMDnsSd::DnssdHostRegistration::Register(void)

otbrLogInfo("Registering new host %s", mName.c_str());

VerifyOrExit(GetPublisher().IsStarted(), dnsError = kDNSServiceErr_ServiceNotRunning);

for (const Ip6Address &address : mAddresses)
{
DNSRecordRef recordRef = nullptr;
Expand Down Expand Up @@ -590,6 +596,7 @@ void PublisherMDnsSd::DnssdHostRegistration::Unregister(void)
{
DNSServiceErrorType dnsError;

VerifyOrExit(GetPublisher().IsStarted());
VerifyOrExit(GetPublisher().mHostsRef != nullptr);

for (size_t index = 0; index < mAddrRecordRefs.size(); index++)
Expand Down Expand Up @@ -674,6 +681,8 @@ otbrError PublisherMDnsSd::DnssdKeyRegistration::Register(void)

otbrLogInfo("Registering new key %s", mName.c_str());

VerifyOrExit(GetPublisher().IsStarted(), dnsError = kDNSServiceErr_ServiceNotRunning);

serviceReg = static_cast<DnssdServiceRegistration *>(GetPublisher().FindServiceRegistration(mName));

if ((serviceReg != nullptr) && (serviceReg->mServiceRef != nullptr))
Expand Down Expand Up @@ -743,6 +752,8 @@ void PublisherMDnsSd::DnssdKeyRegistration::Unregister(void)
otbrLogInfo("Unregistering key %s (was registered individually)", mName.c_str());
}

VerifyOrExit(GetPublisher().IsStarted(), dnsError = kDNSServiceErr_ServiceNotRunning);

VerifyOrExit(serviceRef != nullptr);

dnsError = DNSServiceRemoveRecord(serviceRef, mRecordRef, /* flags */ 0);
Expand Down

0 comments on commit f2a897e

Please sign in to comment.