summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-11-08 14:29:17 (GMT)
committerTobias Markmann <tm@ayena.de>2016-11-18 08:49:39 (GMT)
commit43479ef719ea8fc6abbf654730b47c4583140508 (patch)
treec0a05a837b8988c0875fedb6161c08f3dcb2ffb0 /Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
parentc82f95fd431e702137d5f2e3dda4cf0ae424e837 (diff)
downloadswift-43479ef719ea8fc6abbf654730b47c4583140508.zip
swift-43479ef719ea8fc6abbf654730b47c4583140508.tar.bz2
Improve string to HostAddress conversion API
Previously HostAddress had a constructor which allowed initialisation via a std::string. This initialisation can fail and this is heavily used for checking whether a string is a valid IP address. This constructor is removed in this commit and replaced by a static method HostAddress::fromString, taking a string and returning an optional HostAddress. This clearly communicates that the conversion can fail. Test-Information: ./scons test=all passes on macOS 10.12.1. Change-Id: Idaafee6f84010ce541c55f267ac77ad6ac8f02b4
Diffstat (limited to 'Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp')
-rw-r--r--Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
index 2975193..09b664f 100644
--- a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
+++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
@@ -18,7 +18,6 @@
#include <boost/bind.hpp>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/JingleS5BTransportPayload.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamServerManager.h>
@@ -140,7 +139,7 @@ void LocalJingleTransportCandidateGenerator::emitOnLocalTransportCandidatesGener
if (options_.isDirectAllowed()) {
// get direct candidates
std::vector<HostAddressPort> directCandidates = s5bServerManager->getHostAddressPorts();
- foreach(HostAddressPort addressPort, directCandidates) {
+ for(auto&& addressPort : directCandidates) {
if (addressPort.getAddress().getRawAddress().is_v6() &&
addressPort.getAddress().getRawAddress().to_v6().is_link_local()) {
continue;
@@ -158,7 +157,7 @@ void LocalJingleTransportCandidateGenerator::emitOnLocalTransportCandidatesGener
if (options_.isAssistedAllowed()) {
// get assissted candidates
std::vector<HostAddressPort> assisstedCandidates = s5bServerManager->getAssistedHostAddressPorts();
- foreach(HostAddressPort addressPort, assisstedCandidates) {
+ for (auto&& addressPort : assisstedCandidates) {
JingleS5BTransportPayload::Candidate candidate;
candidate.type = JingleS5BTransportPayload::Candidate::AssistedType;
candidate.jid = ownJID;
@@ -170,17 +169,18 @@ void LocalJingleTransportCandidateGenerator::emitOnLocalTransportCandidatesGener
}
if (options_.isProxiedAllowed() && s5bProxy->getOrDiscoverS5BProxies().is_initialized()) {
- foreach(S5BProxyRequest::ref proxy, s5bProxy->getOrDiscoverS5BProxies().get()) {
+ for (auto&& proxy : s5bProxy->getOrDiscoverS5BProxies().get()) {
if (proxy->getStreamHost()) { // FIXME: Added this test, because there were cases where this wasn't initialized. Investigate this. (Remko)
JingleS5BTransportPayload::Candidate candidate;
candidate.type = JingleS5BTransportPayload::Candidate::ProxyType;
candidate.jid = (*proxy->getStreamHost()).jid;
- HostAddress address = (*proxy->getStreamHost()).host;
- assert(address.isValid());
- candidate.hostPort = HostAddressPort(address, (*proxy->getStreamHost()).port);
- candidate.priority = 65536 * 10 + LOCAL_PREFERENCE;
- candidate.cid = idGenerator->generateID();
- candidates.push_back(candidate);
+ auto address = HostAddress::fromString((*proxy->getStreamHost()).host);
+ if (address) {
+ candidate.hostPort = HostAddressPort(address.get(), (*proxy->getStreamHost()).port);
+ candidate.priority = 65536 * 10 + LOCAL_PREFERENCE;
+ candidate.cid = idGenerator->generateID();
+ candidates.push_back(candidate);
+ }
}
}
}