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
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')
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp5
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h24
-rw-r--r--Swiften/LinkLocal/DNSSD/DNSSDQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h6
-rw-r--r--Swiften/LinkLocal/LinkLocalService.h4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.cpp4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.h4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.cpp10
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.h8
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp6
17 files changed, 66 insertions, 45 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp
index 1b79946..66b4ae8 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.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 */
@@ -25,7 +25,7 @@ std::shared_ptr<DNSSDBrowseQuery> AvahiQuerier::createBrowseQuery() {
25 return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop); 25 return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop);
26} 26}
27 27
28std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 28std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
29 return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop); 29 return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop);
30} 30}
31 31
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h
index 5dce19d..73dd11d 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.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 */
@@ -30,7 +30,7 @@ namespace Swift {
30 30
31 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); 31 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
32 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 32 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
33 const std::string& name, int port, const ByteArray& info); 33 const std::string& name, unsigned short port, const ByteArray& info);
34 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 34 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
35 const DNSSDServiceID&); 35 const DNSSDServiceID&);
36 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 36 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
index 68281d0..b780043 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.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 */
@@ -18,7 +18,7 @@ namespace Swift {
18 18
19 class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery { 19 class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery {
20 public: 20 public:
21 AvahiRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) { 21 AvahiRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) {
22 } 22 }
23 23
24 void registerService(); 24 void registerService();
@@ -50,7 +50,7 @@ namespace Swift {
50 50
51 private: 51 private:
52 std::string name; 52 std::string name;
53 int port; 53 unsigned short port;
54 ByteArray txtRecord; 54 ByteArray txtRecord;
55 AvahiEntryGroup* group; 55 AvahiEntryGroup* group;
56 }; 56 };
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
39std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 40std::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:
diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h
index 8f3c3ec..3924c05 100644
--- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.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 */
@@ -26,7 +26,7 @@ namespace Swift {
26 26
27 virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0; 27 virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0;
28 virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 28 virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
29 const std::string& name, int port, const ByteArray& info) = 0; 29 const std::string& name, unsigned short port, const ByteArray& info) = 0;
30 virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 30 virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
31 const DNSSDServiceID&) = 0; 31 const DNSSDServiceID&) = 0;
32 virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 32 virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h
index b55447a..6416d69 100644
--- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h
+++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.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 */
@@ -16,11 +16,11 @@ namespace Swift {
16 class DNSSDResolveServiceQuery { 16 class DNSSDResolveServiceQuery {
17 public: 17 public:
18 struct Result { 18 struct Result {
19 Result(const std::string& fullName, const std::string& host, int port, const ByteArray& info) : 19 Result(const std::string& fullName, const std::string& host, unsigned short port, const ByteArray& info) :
20 fullName(fullName), host(host), port(port), info(info) {} 20 fullName(fullName), host(host), port(port), info(info) {}
21 std::string fullName; 21 std::string fullName;
22 std::string host; 22 std::string host;
23 int port; 23 unsigned short port;
24 ByteArray info; 24 ByteArray info;
25 }; 25 };
26 26
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
index c17f8b2..3381a26 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.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 */
@@ -32,7 +32,7 @@ std::shared_ptr<DNSSDBrowseQuery> FakeDNSSDQuerier::createBrowseQuery() {
32 return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this()); 32 return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this());
33} 33}
34 34
35std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 35std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
36 return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this()); 36 return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this());
37} 37}
38 38
@@ -105,7 +105,7 @@ void FakeDNSSDQuerier::setServiceInfo(const DNSSDServiceID& id, const DNSSDResol
105 } 105 }
106} 106}
107 107
108bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, int port, const ByteArray& info) { 108bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info) {
109 for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) { 109 for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) {
110 if (query->name == name && query->port == port && query->info == info) { 110 if (query->name == name && query->port == port && query->info == info) {
111 return true; 111 return true;
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
index 5d4fefd..07cb75c 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2017 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 */
@@ -39,7 +39,7 @@ namespace Swift {
39 39
40 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); 40 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
41 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 41 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
42 const std::string& name, int port, const ByteArray& info); 42 const std::string& name, unsigned short port, const ByteArray& info);
43 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 43 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
44 const DNSSDServiceID&); 44 const DNSSDServiceID&);
45 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 45 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
@@ -51,7 +51,7 @@ namespace Swift {
51 void addService(const DNSSDServiceID& id); 51 void addService(const DNSSDServiceID& id);
52 void removeService(const DNSSDServiceID& id); 52 void removeService(const DNSSDServiceID& id);
53 void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info); 53 void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info);
54 bool isServiceRegistered(const std::string& name, int port, const ByteArray& info); 54 bool isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info);
55 void setAddress(const std::string& hostname, boost::optional<HostAddress> address); 55 void setAddress(const std::string& hostname, boost::optional<HostAddress> address);
56 56
57 void setBrowseError(); 57 void setBrowseError();
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h
index 7478841..ee6bb92 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.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 */
@@ -17,7 +17,7 @@ namespace Swift {
17 17
18 class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery { 18 class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery {
19 public: 19 public:
20 FakeDNSSDRegisterQuery(const std::string& name, int port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { 20 FakeDNSSDRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) {
21 } 21 }
22 22
23 void registerService() { 23 void registerService() {
@@ -33,7 +33,7 @@ namespace Swift {
33 } 33 }
34 34
35 std::string name; 35 std::string name;
36 int port; 36 unsigned short port;
37 ByteArray info; 37 ByteArray info;
38 }; 38 };
39} 39}
diff --git a/Swiften/LinkLocal/LinkLocalService.h b/Swiften/LinkLocal/LinkLocalService.h
index 9b0e2ab..c51f890 100644
--- a/Swiften/LinkLocal/LinkLocalService.h
+++ b/Swiften/LinkLocal/LinkLocalService.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 */
@@ -31,7 +31,7 @@ namespace Swift {
31 return id.getName(); 31 return id.getName();
32 } 32 }
33 33
34 int getPort() const { 34 unsigned short getPort() const {
35 return info.port; 35 return info.port;
36 } 36 }
37 37
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
index b79f184..b3328cd 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.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 */
@@ -65,7 +65,7 @@ bool LinkLocalServiceBrowser::isRegistered() const {
65 return !!registerQuery; 65 return !!registerQuery;
66} 66}
67 67
68void LinkLocalServiceBrowser::registerService(const std::string& name, int port, const LinkLocalServiceInfo& info) { 68void LinkLocalServiceBrowser::registerService(const std::string& name, unsigned short port, const LinkLocalServiceInfo& info) {
69 assert(!registerQuery); 69 assert(!registerQuery);
70 registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord()); 70 registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord());
71 registerQuery->onRegisterFinished.connect( 71 registerQuery->onRegisterFinished.connect(
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.h b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
index c59a4d0..bfcfc07 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.h
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.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 */
@@ -35,7 +35,7 @@ namespace Swift {
35 35
36 void registerService( 36 void registerService(
37 const std::string& name, 37 const std::string& name,
38 int port, 38 unsigned short port,
39 const LinkLocalServiceInfo& info = LinkLocalServiceInfo()); 39 const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
40 void updateService( 40 void updateService(
41 const LinkLocalServiceInfo& info = LinkLocalServiceInfo()); 41 const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
index 771251a..102b7f3 100644
--- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2013 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 */
@@ -82,7 +82,13 @@ LinkLocalServiceInfo LinkLocalServiceInfo::createFromTXTRecord(const ByteArray&
82 info.setNick(entry.second); 82 info.setNick(entry.second);
83 } 83 }
84 else if (entry.first == "port.p2pj") { 84 else if (entry.first == "port.p2pj") {
85 info.setPort(boost::lexical_cast<int>(entry.second)); 85 try {
86 info.setPort(boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(entry.second)));
87 }
88 catch (const boost::bad_lexical_cast&) {
89 }
90 catch (const boost::numeric::bad_numeric_cast&) {
91 }
86 } 92 }
87 else if (entry.first == "status") { 93 else if (entry.first == "status") {
88 if (entry.second == "away") { 94 if (entry.second == "away") {
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.h b/Swiften/LinkLocal/LinkLocalServiceInfo.h
index 9f15c6e..eb65706 100644
--- a/Swiften/LinkLocal/LinkLocalServiceInfo.h
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.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 */
@@ -43,8 +43,8 @@ namespace Swift {
43 Status getStatus() const { return status; } 43 Status getStatus() const { return status; }
44 void setStatus(Status s) { status = s; } 44 void setStatus(Status s) { status = s; }
45 45
46 boost::optional<int> getPort() const { return port; } 46 boost::optional<unsigned short> getPort() const { return port; }
47 void setPort(int p) { port = p; } 47 void setPort(unsigned short p) { port = p; }
48 48
49 ByteArray toTXTRecord() const; 49 ByteArray toTXTRecord() const;
50 50
@@ -62,6 +62,6 @@ namespace Swift {
62 std::string message; 62 std::string message;
63 std::string nick; 63 std::string nick;
64 Status status; 64 Status status;
65 boost::optional<int> port; 65 boost::optional<unsigned short> port;
66 }; 66 };
67} 67}
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
index 85ae537..ab1ee0c 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.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 */
@@ -53,7 +53,7 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
53 CPPUNIT_ASSERT(!connectError); 53 CPPUNIT_ASSERT(!connectError);
54 CPPUNIT_ASSERT(connection->connectedTo); 54 CPPUNIT_ASSERT(connection->connectedTo);
55 CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1")); 55 CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1"));
56 CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234); 56 CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), static_cast<unsigned short>(1234));
57 } 57 }
58 58
59 void testConnect_UnableToResolve() { 59 void testConnect_UnableToResolve() {
@@ -114,7 +114,7 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
114 } 114 }
115 115
116 private: 116 private:
117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) { 117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) {
118 LinkLocalService service( 118 LinkLocalService service(
119 DNSSDServiceID("myname", "local."), 119 DNSSDServiceID("myname", "local."),
120 DNSSDResolveServiceQuery::Result( 120 DNSSDResolveServiceQuery::Result(