From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp | 215 ++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp (limited to 'netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp') diff --git a/netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp b/netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp new file mode 100644 index 0000000000..ee08a87211 --- /dev/null +++ b/netwerk/dns/mdns/libmdns/MDNSResponderReply.cpp @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "MDNSResponderReply.h" +#include "mozilla/EndianUtils.h" +#include "private/pprio.h" + +namespace mozilla { +namespace net { + +BrowseReplyRunnable::BrowseReplyRunnable( + DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, const nsACString& aServiceName, + const nsACString& aRegType, const nsACString& aReplyDomain, + BrowseOperator* aContext) + : Runnable("net::BrowseReplyRunnable"), + mSdRef(aSdRef), + mFlags(aFlags), + mInterfaceIndex(aInterfaceIndex), + mErrorCode(aErrorCode), + mServiceName(aServiceName), + mRegType(aRegType), + mReplyDomain(aReplyDomain), + mContext(aContext) {} + +NS_IMETHODIMP +BrowseReplyRunnable::Run() { + MOZ_ASSERT(mContext); + mContext->Reply(mSdRef, mFlags, mInterfaceIndex, mErrorCode, mServiceName, + mRegType, mReplyDomain); + return NS_OK; +} + +void BrowseReplyRunnable::Reply(DNSServiceRef aSdRef, DNSServiceFlags aFlags, + uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, + const char* aServiceName, const char* aRegType, + const char* aReplyDomain, void* aContext) { + MOZ_ASSERT(OnSocketThread(), "not on socket thread"); + + BrowseOperator* obj(reinterpret_cast(aContext)); + if (!obj) { + return; + } + + nsCOMPtr thread(obj->GetThread()); + if (!thread) { + return; + } + + thread->Dispatch( + new BrowseReplyRunnable(aSdRef, aFlags, aInterfaceIndex, aErrorCode, + nsCString(aServiceName), nsCString(aRegType), + nsCString(aReplyDomain), obj), + NS_DISPATCH_NORMAL); +} + +RegisterReplyRunnable::RegisterReplyRunnable(DNSServiceRef aSdRef, + DNSServiceFlags aFlags, + DNSServiceErrorType aErrorCode, + const nsACString& aName, + const nsACString& aRegType, + const nsACString& domain, + RegisterOperator* aContext) + : Runnable("net::RegisterReplyRunnable"), + mSdRef(aSdRef), + mFlags(aFlags), + mErrorCode(aErrorCode), + mName(aName), + mRegType(aRegType), + mDomain(domain), + mContext(aContext) {} + +NS_IMETHODIMP +RegisterReplyRunnable::Run() { + MOZ_ASSERT(mContext); + + mContext->Reply(mSdRef, mFlags, mErrorCode, mName, mRegType, mDomain); + return NS_OK; +} + +void RegisterReplyRunnable::Reply(DNSServiceRef aSdRef, DNSServiceFlags aFlags, + DNSServiceErrorType aErrorCode, + const char* aName, const char* aRegType, + const char* domain, void* aContext) { + MOZ_ASSERT(OnSocketThread(), "not on socket thread"); + + RegisterOperator* obj(reinterpret_cast(aContext)); + if (!obj) { + return; + } + + nsCOMPtr thread(obj->GetThread()); + if (!thread) { + return; + } + + thread->Dispatch( + new RegisterReplyRunnable(aSdRef, aFlags, aErrorCode, nsCString(aName), + nsCString(aRegType), nsCString(domain), obj), + NS_DISPATCH_NORMAL); +} + +ResolveReplyRunnable::ResolveReplyRunnable( + DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, const nsACString& aFullName, + const nsACString& aHostTarget, uint16_t aPort, uint16_t aTxtLen, + const unsigned char* aTxtRecord, ResolveOperator* aContext) + : Runnable("net::ResolveReplyRunnable"), + mSdRef(aSdRef), + mFlags(aFlags), + mInterfaceIndex(aInterfaceIndex), + mErrorCode(aErrorCode), + mFullname(aFullName), + mHosttarget(aHostTarget), + mPort(aPort), + mTxtLen(aTxtLen), + mTxtRecord(new unsigned char[aTxtLen]), + mContext(aContext) { + if (mTxtRecord) { + memcpy(mTxtRecord.get(), aTxtRecord, aTxtLen); + } +} + +NS_IMETHODIMP +ResolveReplyRunnable::Run() { + MOZ_ASSERT(mContext); + mContext->Reply(mSdRef, mFlags, mInterfaceIndex, mErrorCode, mFullname, + mHosttarget, mPort, mTxtLen, mTxtRecord.get()); + return NS_OK; +} + +void ResolveReplyRunnable::Reply(DNSServiceRef aSdRef, DNSServiceFlags aFlags, + uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, + const char* aFullName, const char* aHostTarget, + uint16_t aPort, uint16_t aTxtLen, + const unsigned char* aTxtRecord, + void* aContext) { + MOZ_ASSERT(OnSocketThread(), "not on socket thread"); + + ResolveOperator* obj(reinterpret_cast(aContext)); + if (!obj) { + return; + } + + nsCOMPtr thread(obj->GetThread()); + if (!thread) { + return; + } + + thread->Dispatch( + new ResolveReplyRunnable(aSdRef, aFlags, aInterfaceIndex, aErrorCode, + nsCString(aFullName), nsCString(aHostTarget), + NativeEndian::swapFromNetworkOrder(aPort), + aTxtLen, aTxtRecord, obj), + NS_DISPATCH_NORMAL); +} + +GetAddrInfoReplyRunnable::GetAddrInfoReplyRunnable( + DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, const nsACString& aHostName, + const mozilla::net::NetAddr& aAddress, uint32_t aTTL, + GetAddrInfoOperator* aContext) + : Runnable("net::GetAddrInfoReplyRunnable"), + mSdRef(aSdRef), + mFlags(aFlags), + mInterfaceIndex(aInterfaceIndex), + mErrorCode(aErrorCode), + mHostName(aHostName), + mAddress(aAddress), + mTTL(aTTL), + mContext(aContext) {} + +NS_IMETHODIMP +GetAddrInfoReplyRunnable::Run() { + MOZ_ASSERT(mContext); + mContext->Reply(mSdRef, mFlags, mInterfaceIndex, mErrorCode, mHostName, + mAddress, mTTL); + return NS_OK; +} + +void GetAddrInfoReplyRunnable::Reply( + DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, + DNSServiceErrorType aErrorCode, const char* aHostName, + const struct sockaddr* aAddress, uint32_t aTTL, void* aContext) { + MOZ_ASSERT(OnSocketThread(), "not on socket thread"); + + GetAddrInfoOperator* obj(reinterpret_cast(aContext)); + if (!obj) { + return; + } + + nsCOMPtr thread(obj->GetThread()); + if (!thread) { + return; + } + + NetAddr address; + address.raw.family = aAddress->sa_family; + + static_assert(sizeof(address.raw.data) >= sizeof(aAddress->sa_data), + "size of sockaddr.sa_data is too big"); + memcpy(&address.raw.data, aAddress->sa_data, sizeof(aAddress->sa_data)); + + thread->Dispatch( + new GetAddrInfoReplyRunnable(aSdRef, aFlags, aInterfaceIndex, aErrorCode, + nsCString(aHostName), address, aTTL, obj), + NS_DISPATCH_NORMAL); +} + +} // namespace net +} // namespace mozilla -- cgit v1.2.3