diff options
| author | Edwin Mons <edwin.mons@isode.com> | 2018-10-29 16:28:14 (GMT) |
|---|---|---|
| committer | Edwin Mons <edwin.mons@isode.com> | 2018-11-08 11:31:20 (GMT) |
| commit | cf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f (patch) | |
| tree | 69e11e13ff2e5127d2cbfcc164be761cf104a1b2 /Swiften/LinkLocal/DNSSD/Bonjour | |
| parent | 5ce9e19ef0744f530a797c30a82e9723eb7ea306 (diff) | |
| download | swift-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')
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp | 5 | ||||
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h | 4 | ||||
| -rw-r--r-- | Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h | 24 |
3 files changed, 24 insertions, 9 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp index 0906ffc..551421e 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <unistd.h> | 11 | #include <unistd.h> |
| 12 | 12 | ||
| 13 | #include <Swiften/Base/Algorithm.h> | 13 | #include <Swiften/Base/Algorithm.h> |
| 14 | #include <Swiften/Base/Log.h> | ||
| 14 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h> | 15 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h> |
| 15 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h> | 16 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h> |
| 16 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h> | 17 | #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h> |
| @@ -36,7 +37,7 @@ std::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() { | |||
| 36 | return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop); | 37 | return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop); |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 39 | std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { | 40 | std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) { |
| 40 | return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop); | 41 | return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop); |
| 41 | } | 42 | } |
| 42 | 43 | ||
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index 77326bc..6af1c1f 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -25,7 +25,7 @@ namespace Swift { | |||
| 25 | 25 | ||
| 26 | std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); | 26 | std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); |
| 27 | std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( | 27 | std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( |
| 28 | const std::string& name, int port, const ByteArray& info); | 28 | const std::string& name, unsigned short port, const ByteArray& info); |
| 29 | std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( | 29 | std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( |
| 30 | const DNSSDServiceID&); | 30 | const DNSSDServiceID&); |
| 31 | std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( | 31 | std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( |
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 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -20,12 +20,21 @@ namespace Swift { | |||
| 20 | 20 | ||
| 21 | class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { | 21 | class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { |
| 22 | public: | 22 | public: |
| 23 | BonjourRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { | 23 | BonjourRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { |
| 24 | unsigned short recordSize = 0; | ||
| 25 | try { | ||
| 26 | recordSize = boost::numeric_cast<unsigned short>(txtRecord.size()); | ||
| 27 | } | ||
| 28 | catch (const boost::numeric::bad_numeric_cast&) { | ||
| 29 | SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not registring service" << std::endl; | ||
| 30 | return; | ||
| 31 | } | ||
| 24 | DNSServiceErrorType result = DNSServiceRegister( | 32 | DNSServiceErrorType result = DNSServiceRegister( |
| 25 | &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, boost::numeric_cast<unsigned short>(port), | 33 | &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, port, |
| 26 | boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), | 34 | recordSize, vecptr(txtRecord), |
| 27 | &BonjourRegisterQuery::handleServiceRegisteredStatic, this); | 35 | &BonjourRegisterQuery::handleServiceRegisteredStatic, this); |
| 28 | if (result != kDNSServiceErr_NoError) { | 36 | if (result != kDNSServiceErr_NoError) { |
| 37 | SWIFT_LOG(warning) << "Failed to register Bonjour service" << std::endl; | ||
| 29 | sdRef = nullptr; | 38 | sdRef = nullptr; |
| 30 | } | 39 | } |
| 31 | } | 40 | } |
| @@ -45,7 +54,12 @@ namespace Swift { | |||
| 45 | 54 | ||
| 46 | void updateServiceInfo(const ByteArray& txtRecord) { | 55 | void updateServiceInfo(const ByteArray& txtRecord) { |
| 47 | std::lock_guard<std::mutex> lock(sdRefMutex); | 56 | std::lock_guard<std::mutex> lock(sdRefMutex); |
| 48 | DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); | 57 | try { |
| 58 | DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); | ||
| 59 | } | ||
| 60 | catch (const boost::numeric::bad_numeric_cast&) { | ||
| 61 | SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not updating service record" << std::endl; | ||
| 62 | } | ||
| 49 | } | 63 | } |
| 50 | 64 | ||
| 51 | private: | 65 | private: |
Swift