summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h>
@@ -22,13 +22,13 @@ AvahiQuerier::~AvahiQuerier() {
}
std::shared_ptr<DNSSDBrowseQuery> AvahiQuerier::createBrowseQuery() {
return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop);
}
-std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) {
+std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop);
}
std::shared_ptr<DNSSDResolveServiceQuery> AvahiQuerier::createResolveServiceQuery(const DNSSDServiceID& service) {
return std::make_shared<AvahiResolveServiceQuery>(service, shared_from_this(), eventLoop);
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -27,13 +27,13 @@ namespace Swift {
public:
AvahiQuerier(EventLoop* eventLoop);
~AvahiQuerier();
std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
- const std::string& name, int port, const ByteArray& info);
+ const std::string& name, unsigned short port, const ByteArray& info);
std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
const DNSSDServiceID&);
std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
const std::string& hostname, int interfaceIndex);
void start();
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -15,13 +15,13 @@
namespace Swift {
class AvahiQuerier;
class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery {
public:
- 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) {
+ 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) {
}
void registerService();
void unregisterService();
void updateServiceInfo(const ByteArray& txtRecord);
@@ -47,11 +47,11 @@ namespace Swift {
}
}
*/
private:
std::string name;
- int port;
+ unsigned short port;
ByteArray txtRecord;
AvahiEntryGroup* group;
};
}
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,19 +1,20 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <Swiften/Base/Algorithm.h>
+#include <Swiften/Base/Log.h>
#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h>
#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h>
#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h>
#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h>
namespace Swift {
@@ -33,13 +34,13 @@ BonjourQuerier::~BonjourQuerier() {
}
std::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() {
return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop);
}
-std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) {
+std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop);
}
std::shared_ptr<DNSSDResolveServiceQuery> BonjourQuerier::createResolveServiceQuery(const DNSSDServiceID& service) {
return std::make_shared<BonjourResolveServiceQuery>(service, shared_from_this(), eventLoop);
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -22,13 +22,13 @@ namespace Swift {
public:
BonjourQuerier(EventLoop* eventLoop);
~BonjourQuerier();
std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
- const std::string& name, int port, const ByteArray& info);
+ const std::string& name, unsigned short port, const ByteArray& info);
std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
const DNSSDServiceID&);
std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
const std::string& hostname, int interfaceIndex);
void start();
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -17,18 +17,27 @@
namespace Swift {
class BonjourQuerier;
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;
}
}
void registerService() {
if (sdRef) {
@@ -42,13 +51,18 @@ namespace Swift {
void unregisterService() {
finish();
}
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:
static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) {
static_cast<BonjourRegisterQuery*>(context)->handleServiceRegistered(errorCode, name, regtype, domain);
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -23,13 +23,13 @@ namespace Swift {
virtual void start() = 0;
virtual void stop() = 0;
virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0;
virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
- const std::string& name, int port, const ByteArray& info) = 0;
+ const std::string& name, unsigned short port, const ByteArray& info) = 0;
virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
const DNSSDServiceID&) = 0;
virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
const std::string& hostname, int interfaceIndex) = 0;
};
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -13,17 +13,17 @@
#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h>
namespace Swift {
class DNSSDResolveServiceQuery {
public:
struct Result {
- Result(const std::string& fullName, const std::string& host, int port, const ByteArray& info) :
+ Result(const std::string& fullName, const std::string& host, unsigned short port, const ByteArray& info) :
fullName(fullName), host(host), port(port), info(info) {}
std::string fullName;
std::string host;
- int port;
+ unsigned short port;
ByteArray info;
};
virtual ~DNSSDResolveServiceQuery();
virtual void start() = 0;
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h>
@@ -29,13 +29,13 @@ FakeDNSSDQuerier::~FakeDNSSDQuerier() {
}
std::shared_ptr<DNSSDBrowseQuery> FakeDNSSDQuerier::createBrowseQuery() {
return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this());
}
-std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) {
+std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this());
}
std::shared_ptr<DNSSDResolveServiceQuery> FakeDNSSDQuerier::createResolveServiceQuery(const DNSSDServiceID& service) {
return std::make_shared<FakeDNSSDResolveServiceQuery>(service, shared_from_this());
}
@@ -102,13 +102,13 @@ void FakeDNSSDQuerier::setServiceInfo(const DNSSDServiceID& id, const DNSSDResol
if (query->service == id) {
eventLoop->postEvent(boost::bind(boost::ref(query->onServiceResolved), info), shared_from_this());
}
}
}
-bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, int port, const ByteArray& info) {
+bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info) {
for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) {
if (query->name == name && query->port == port && query->info == info) {
return true;
}
}
return false;
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2017 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -36,25 +36,25 @@ namespace Swift {
void clearAllQueriesEverRun() {
allQueriesEverRun.clear();
}
std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
- const std::string& name, int port, const ByteArray& info);
+ const std::string& name, unsigned short port, const ByteArray& info);
std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
const DNSSDServiceID&);
std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
const std::string& hostname, int interfaceIndex);
void addRunningQuery(std::shared_ptr<FakeDNSSDQuery>);
void removeRunningQuery(std::shared_ptr<FakeDNSSDQuery>);
void addService(const DNSSDServiceID& id);
void removeService(const DNSSDServiceID& id);
void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info);
- bool isServiceRegistered(const std::string& name, int port, const ByteArray& info);
+ bool isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info);
void setAddress(const std::string& hostname, boost::optional<HostAddress> address);
void setBrowseError();
void setRegisterError();
public:
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -14,13 +14,13 @@
namespace Swift {
class FakeDNSSDQuerier;
class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery {
public:
- FakeDNSSDRegisterQuery(const std::string& name, int port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) {
+ FakeDNSSDRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) {
}
void registerService() {
run();
}
@@ -30,10 +30,10 @@ namespace Swift {
void unregisterService() {
finish();
}
std::string name;
- int port;
+ unsigned short port;
ByteArray info;
};
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -28,13 +28,13 @@ namespace Swift {
}
const std::string& getName() const {
return id.getName();
}
- int getPort() const {
+ unsigned short getPort() const {
return info.port;
}
const std::string& getHostname() const {
return info.host;
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h>
@@ -62,13 +62,13 @@ bool LinkLocalServiceBrowser::hasError() const {
}
bool LinkLocalServiceBrowser::isRegistered() const {
return !!registerQuery;
}
-void LinkLocalServiceBrowser::registerService(const std::string& name, int port, const LinkLocalServiceInfo& info) {
+void LinkLocalServiceBrowser::registerService(const std::string& name, unsigned short port, const LinkLocalServiceInfo& info) {
assert(!registerQuery);
registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord());
registerQuery->onRegisterFinished.connect(
boost::bind(&LinkLocalServiceBrowser::handleRegisterFinished, this, _1));
registerQuery->registerService();
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -32,13 +32,13 @@ namespace Swift {
void stop();
bool isRunning() const;
bool hasError() const;
void registerService(
const std::string& name,
- int port,
+ unsigned short port,
const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
void updateService(
const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
void unregisterService();
bool isRegistered() const;
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/LinkLocal/LinkLocalServiceInfo.h>
@@ -79,13 +79,19 @@ LinkLocalServiceInfo LinkLocalServiceInfo::createFromTXTRecord(const ByteArray&
info.setMessage(entry.second);
}
else if (entry.first == "nick") {
info.setNick(entry.second);
}
else if (entry.first == "port.p2pj") {
- info.setPort(boost::lexical_cast<int>(entry.second));
+ try {
+ info.setPort(boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(entry.second)));
+ }
+ catch (const boost::bad_lexical_cast&) {
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
+ }
}
else if (entry.first == "status") {
if (entry.second == "away") {
info.setStatus(Away);
}
else if (entry.second == "dnd") {
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -40,14 +40,14 @@ namespace Swift {
const std::string& getNick() const { return nick; }
void setNick(const std::string& n) { nick = n; }
Status getStatus() const { return status; }
void setStatus(Status s) { status = s; }
- boost::optional<int> getPort() const { return port; }
- void setPort(int p) { port = p; }
+ boost::optional<unsigned short> getPort() const { return port; }
+ void setPort(unsigned short p) { port = p; }
ByteArray toTXTRecord() const;
static LinkLocalServiceInfo createFromTXTRecord(const ByteArray& record);
private:
@@ -59,9 +59,9 @@ namespace Swift {
std::string lastName;
std::string email;
JID jid;
std::string message;
std::string nick;
Status status;
- boost::optional<int> port;
+ boost::optional<unsigned short> port;
};
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <boost/bind.hpp>
@@ -50,13 +50,13 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
eventLoop->processEvents();
CPPUNIT_ASSERT(connectFinished);
CPPUNIT_ASSERT(!connectError);
CPPUNIT_ASSERT(connection->connectedTo);
CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1"));
- CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234);
+ CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), static_cast<unsigned short>(1234));
}
void testConnect_UnableToResolve() {
std::shared_ptr<LinkLocalConnector>
testling(createConnector("rabbithole.local", 1234));
querier->setAddress("rabbithole.local", boost::optional<HostAddress>());
@@ -111,13 +111,13 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
eventLoop->processEvents();
CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state);
}
private:
- std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) {
+ std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) {
LinkLocalService service(
DNSSDServiceID("myname", "local."),
DNSSDResolveServiceQuery::Result(
"myname._presence._tcp.local", hostname, port,
LinkLocalServiceInfo().toTXTRecord()));
std::shared_ptr<LinkLocalConnector> result(