summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-10-29 16:28:14 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-08 11:31:20 (GMT)
commitcf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f (patch)
tree69e11e13ff2e5127d2cbfcc164be761cf104a1b2 /Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
parent5ce9e19ef0744f530a797c30a82e9723eb7ea306 (diff)
downloadswift-cf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f.zip
swift-cf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f.tar.bz2
Consistently use unsigned short for network ports
Network ports are now consistently stored as unsigned shorts, apart from the options and user interface, where -1 is still used to denote the use of default ports. Test-Information: Unit tests pass on macOS 10.13 and Debian 9 On macOS: tested the UI with various proxy and manual ports, behaviour as expected. Change-Id: I7a65f40083022887aa30ed7b21eadc56d0c52be1
Diffstat (limited to 'Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h')
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h24
1 files changed, 19 insertions, 5 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
index 8b2e955..9eb8cd9 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -20,12 +20,21 @@ namespace Swift {
class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery {
public:
- BonjourRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
+ BonjourRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
+ unsigned short recordSize = 0;
+ try {
+ recordSize = boost::numeric_cast<unsigned short>(txtRecord.size());
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
+ SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not registring service" << std::endl;
+ return;
+ }
DNSServiceErrorType result = DNSServiceRegister(
- &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, boost::numeric_cast<unsigned short>(port),
- boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord),
+ &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, port,
+ recordSize, vecptr(txtRecord),
&BonjourRegisterQuery::handleServiceRegisteredStatic, this);
if (result != kDNSServiceErr_NoError) {
+ SWIFT_LOG(warning) << "Failed to register Bonjour service" << std::endl;
sdRef = nullptr;
}
}
@@ -45,7 +54,12 @@ namespace Swift {
void updateServiceInfo(const ByteArray& txtRecord) {
std::lock_guard<std::mutex> lock(sdRefMutex);
- DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0);
+ try {
+ DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0);
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
+ SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not updating service record" << std::endl;
+ }
}
private: