diff options
Diffstat (limited to 'Swiften/FileTransfer')
8 files changed, 9 insertions, 18 deletions
diff --git a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp index aefafd9..c6987c0 100644 --- a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp +++ b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp @@ -1,44 +1,43 @@ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/DefaultFileTransferTransporter.h> #include <memory> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/FileTransfer/FailingTransportSession.h> #include <Swiften/FileTransfer/FileTransferOptions.h> #include <Swiften/FileTransfer/IBBReceiveSession.h> #include <Swiften/FileTransfer/IBBReceiveTransportSession.h> #include <Swiften/FileTransfer/IBBSendSession.h> #include <Swiften/FileTransfer/IBBSendTransportSession.h> #include <Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h> #include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h> #include <Swiften/FileTransfer/S5BTransportSession.h> #include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h> #include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> #include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> #include <Swiften/FileTransfer/SOCKS5BytestreamServerManager.h> #include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> #include <Swiften/FileTransfer/TransportSession.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/StringCodecs/Hexify.h> using namespace Swift; DefaultFileTransferTransporter::DefaultFileTransferTransporter( const JID& initiator, const JID& responder, Role role, SOCKS5BytestreamRegistry* s5bRegistry, SOCKS5BytestreamServerManager* s5bServerManager, SOCKS5BytestreamProxiesManager* s5bProxy, IDGenerator* idGenerator, ConnectionFactory* connectionFactory, @@ -268,42 +267,42 @@ std::string DefaultFileTransferTransporter::getSOCKS5DstAddr() const { std::string DefaultFileTransferTransporter::getInitiatorCandidateSOCKS5DstAddr() const { return Hexify::hexify(crypto->getSHA1Hash(createSafeByteArray(s5bSessionID + initiator.toString() + responder.toString()))); } std::string DefaultFileTransferTransporter::getResponderCandidateSOCKS5DstAddr() const { return Hexify::hexify(crypto->getSHA1Hash(createSafeByteArray(s5bSessionID + responder.toString() + initiator.toString()))); } std::string DefaultFileTransferTransporter::getRemoteCandidateSOCKS5DstAddr() const { if (role == Initiator) { return getResponderCandidateSOCKS5DstAddr(); } else { return getInitiatorCandidateSOCKS5DstAddr(); } } std::string DefaultFileTransferTransporter::getLocalCandidateSOCKS5DstAddr() const { if (role == Responder) { return getResponderCandidateSOCKS5DstAddr(); } else { return getInitiatorCandidateSOCKS5DstAddr(); } } void DefaultFileTransferTransporter::closeLocalSession() { s5bRegistry->setHasBytestream(getSOCKS5DstAddr(), false); if (s5bServerManager->getServer()) { std::vector<std::shared_ptr<SOCKS5BytestreamServerSession> > serverSessions = s5bServerManager->getServer()->getSessions(getSOCKS5DstAddr()); - foreach(std::shared_ptr<SOCKS5BytestreamServerSession> session, serverSessions) { + for (auto&& session : serverSessions) { session->stop(); } } } void DefaultFileTransferTransporter::closeRemoteSession() { if (remoteS5BClientSession) { remoteS5BClientSession->stop(); remoteS5BClientSession.reset(); } } diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp index f73cd38..d5de5e4 100644 --- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp @@ -1,45 +1,44 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/IncomingJingleFileTransfer.h> #include <memory> #include <set> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/JingleFileTransferHash.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> #include <Swiften/FileTransfer/FileTransferOptions.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/FileTransfer/FileTransferTransporterFactory.h> #include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> #include <Swiften/FileTransfer/TransportSession.h> #include <Swiften/FileTransfer/WriteBytestream.h> #include <Swiften/Jingle/JingleSession.h> #include <Swiften/Network/TimerFactory.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/StringCodecs/Base64.h> using namespace Swift; // TODO: ALlow terminate when already terminated. IncomingJingleFileTransfer::IncomingJingleFileTransfer( const JID& toJID, JingleSession::ref session, JingleContentPayload::ref content, FileTransferTransporterFactory* transporterFactory, TimerFactory* timerFactory, CryptoProvider* crypto) : JingleFileTransfer(session, toJID, transporterFactory), initialContent(content), crypto(crypto), state(Initial), @@ -103,61 +102,61 @@ void IncomingJingleFileTransfer::accept( description->getFileInfo().getSize(), stream)); session->sendAccept(getContentID(), initialContent->getDescriptions()[0], ibbTransport); } else { // This might happen on incoming transfer which only list transport methods we are not allowed to use due to file-transfer options. session->sendTerminate(JinglePayload::Reason::UnsupportedTransports); setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError)); } } void IncomingJingleFileTransfer::cancel() { SWIFT_LOG(debug) << std::endl; terminate(state == Initial ? JinglePayload::Reason::Decline : JinglePayload::Reason::Cancel); } void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated( const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { SWIFT_LOG(debug) << std::endl; if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } fillCandidateMap(localCandidates, candidates); JingleS5BTransportPayload::ref transport = std::make_shared<JingleS5BTransportPayload>(); transport->setSessionID(s5bSessionID); transport->setMode(JingleS5BTransportPayload::TCPMode); transport->setDstAddr(dstAddr); - foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { + for (auto&& candidate : candidates) { transport->addCandidate(candidate); } session->sendAccept(getContentID(), initialContent->getDescriptions()[0], transport); setState(TryingCandidates); transporter->startTryingRemoteCandidates(); } void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref jinglePayload) { SWIFT_LOG(debug) << std::endl; JingleFileTransferHash::ref transferHash = jinglePayload->getPayload<JingleFileTransferHash>(); if (transferHash) { SWIFT_LOG(debug) << "Received hash information." << std::endl; waitOnHashTimer->stop(); if (transferHash->getFileInfo().getHashes().find("sha-1") != transferHash->getFileInfo().getHashes().end()) { hashes["sha-1"] = transferHash->getFileInfo().getHash("sha-1").get(); } if (transferHash->getFileInfo().getHashes().find("md5") != transferHash->getFileInfo().getHashes().end()) { hashes["md5"] = transferHash->getFileInfo().getHash("md5").get(); } if (state == WaitingForHash) { checkHashAndTerminate(); } } else { SWIFT_LOG(debug) << "Ignoring unknown session info" << std::endl; } } @@ -170,61 +169,61 @@ void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional< SWIFT_LOG(debug) << "Already terminated" << std::endl; return; } stopAll(); if (reason && reason->type == JinglePayload::Reason::Cancel) { setFinishedState(FileTransfer::State::Canceled, FileTransferError(FileTransferError::PeerError)); } else if (reason && reason->type == JinglePayload::Reason::Success) { setFinishedState(FileTransfer::State::Finished, boost::optional<FileTransferError>()); } else { setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError)); } } void IncomingJingleFileTransfer::checkHashAndTerminate() { if (verifyData()) { terminate(JinglePayload::Reason::Success); } else { SWIFT_LOG(warning) << "Hash verification failed" << std::endl; terminate(JinglePayload::Reason::MediaError); } } void IncomingJingleFileTransfer::checkIfAllDataReceived() { if (receivedBytes == getFileSizeInBytes()) { SWIFT_LOG(debug) << "All data received." << std::endl; bool hashInfoAvailable = false; - foreach(const JingleFileTransferFileInfo::HashElementMap::value_type& hashElement, hashes) { + for (const auto& hashElement : hashes) { hashInfoAvailable |= !hashElement.second.empty(); } if (!hashInfoAvailable) { SWIFT_LOG(debug) << "No hash information yet. Waiting a while on hash info." << std::endl; setState(WaitingForHash); waitOnHashTimer->start(); } else { checkHashAndTerminate(); } } else if (receivedBytes > getFileSizeInBytes()) { SWIFT_LOG(debug) << "We got more than we could handle!" << std::endl; terminate(JinglePayload::Reason::MediaError); } } void IncomingJingleFileTransfer::handleWriteStreamDataReceived( const std::vector<unsigned char>& data) { hashCalculator->feedData(data); receivedBytes += data.size(); onProcessedBytes(data.size()); checkIfAllDataReceived(); } void IncomingJingleFileTransfer::handleTransportReplaceReceived( const JingleContentID& content, JingleTransportPayload::ref transport) { SWIFT_LOG(debug) << std::endl; if (state != WaitingForFallbackOrTerminate) { diff --git a/Swiften/FileTransfer/JingleFileTransfer.cpp b/Swiften/FileTransfer/JingleFileTransfer.cpp index 36725de..62c3a53 100644 --- a/Swiften/FileTransfer/JingleFileTransfer.cpp +++ b/Swiften/FileTransfer/JingleFileTransfer.cpp @@ -1,72 +1,71 @@ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/JingleFileTransfer.h> #include <boost/typeof/typeof.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/JID/JID.h> #include <Swiften/Jingle/JingleSession.h> #include <Swiften/StringCodecs/Hexify.h> using namespace Swift; JingleFileTransfer::JingleFileTransfer( std::shared_ptr<JingleSession> session, const JID& target, FileTransferTransporterFactory* transporterFactory) : session(session), target(target), transporterFactory(transporterFactory), transporter(nullptr), ourCandidateSelectFinished(false), theirCandidateSelectFinished(false) { session->addListener(this); } JingleFileTransfer::~JingleFileTransfer() { session->removeListener(this); } void JingleFileTransfer::fillCandidateMap(CandidateMap& map, const std::vector<JingleS5BTransportPayload::Candidate>& candidates) { map.clear(); - foreach (JingleS5BTransportPayload::Candidate candidate, candidates) { + for (auto&& candidate : candidates) { map[candidate.cid] = candidate; } } /* std::string JingleFileTransfer::getS5BDstAddr(const JID& requester, const JID& target) const { return Hexify::hexify(crypto->getSHA1Hash( createSafeByteArray(s5bSessionID + requester.toString() + target.toString()))); } */ const JID& JingleFileTransfer::getInitiator() const { return session->getInitiator(); } const JID& JingleFileTransfer::getResponder() const { return target; } FileTransfer::State::Type JingleFileTransfer::getExternalFinishedState(JinglePayload::Reason::Type reason) { if (reason == JinglePayload::Reason::Cancel || reason == JinglePayload::Reason::Decline) { return FileTransfer::State::Canceled; } else if (reason == JinglePayload::Reason::Success) { return FileTransfer::State::Finished; } else { return FileTransfer::State::Failed; } } diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index fcc160a..367fc97 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -1,57 +1,56 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ // TODO: // - We should handle incoming terminates after we have terminated, so the other // side can warn that he didn't receive all bytes correctly. // - Should the proby stuff also wait for candidate used acknowledgement? #include <Swiften/FileTransfer/OutgoingJingleFileTransfer.h> #include <memory> #include <boost/bind.hpp> #include <boost/typeof/typeof.hpp> #include <Swiften/Base/IDGenerator.h> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/JingleFileTransferHash.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> #include <Swiften/Elements/JingleTransportPayload.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/FileTransfer/FileTransferTransporterFactory.h> #include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> #include <Swiften/FileTransfer/ReadBytestream.h> #include <Swiften/FileTransfer/TransportSession.h> #include <Swiften/Jingle/JingleContentID.h> #include <Swiften/Jingle/JingleSession.h> #include <Swiften/Network/TimerFactory.h> using namespace Swift; static const int DEFAULT_BLOCK_SIZE = 4096; OutgoingJingleFileTransfer::OutgoingJingleFileTransfer( const JID& toJID, JingleSession::ref session, std::shared_ptr<ReadBytestream> stream, FileTransferTransporterFactory* transporterFactory, TimerFactory* timerFactory, IDGenerator* idGenerator, const JingleFileTransferFileInfo& fileInfo, const FileTransferOptions& options, CryptoProvider* crypto) : JingleFileTransfer(session, toJID, transporterFactory), @@ -188,61 +187,61 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() { hashElement->getFileInfo().addHash(HashElement("sha-1", hashCalculator->getSHA1Hash())); hashElement->getFileInfo().addHash(HashElement("md5", hashCalculator->getMD5Hash())); session->sendInfo(hashElement); } void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { SWIFT_LOG(debug) << std::endl; if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } fillCandidateMap(localCandidates, candidates); JingleFileTransferDescription::ref description = std::make_shared<JingleFileTransferDescription>(); fileInfo.addHash(HashElement("sha-1", ByteArray())); fileInfo.addHash(HashElement("md5", ByteArray())); description->setFileInfo(fileInfo); JingleTransportPayload::ref transport; if (candidates.empty()) { SWIFT_LOG(debug) << "no S5B candidates generated. Send IBB transport candidate." << std::endl; JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); ibbTransport->setSessionID(idGenerator->generateID()); transport = ibbTransport; } else { JingleS5BTransportPayload::ref s5bTransport = std::make_shared<JingleS5BTransportPayload>(); s5bTransport->setSessionID(s5bSessionID); s5bTransport->setMode(JingleS5BTransportPayload::TCPMode); s5bTransport->setDstAddr(dstAddr); - foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { + for (auto&& candidate : candidates) { s5bTransport->addCandidate(candidate); SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; } transport = s5bTransport; } setInternalState(WaitingForAccept); session->sendInitiate(contentID, description, transport); } void OutgoingJingleFileTransfer::fallback() { if (options.isInBandAllowed()) { SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl; JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); ibbTransport->setSessionID(idGenerator->generateID()); setInternalState(FallbackRequested); session->sendTransportReplace(contentID, ibbTransport); } else { SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl; terminate(JinglePayload::Reason::ConnectivityError); } } void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) { SWIFT_LOG(debug) << std::endl; if (state != Transferring) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } if (error) { terminate(JinglePayload::Reason::ConnectivityError); diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp index a0e7a6f..56013ca 100644 --- a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp @@ -1,72 +1,71 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h> #include <memory> #include <boost/bind.hpp> #include <boost/signals2.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> #include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> #include <Swiften/Network/ConnectionFactory.h> using namespace Swift; RemoteJingleTransportCandidateSelector::RemoteJingleTransportCandidateSelector( ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const FileTransferOptions& options) : connectionFactory(connectionFactory), timerFactory(timerFactory), options(options) { } RemoteJingleTransportCandidateSelector::~RemoteJingleTransportCandidateSelector() { } void RemoteJingleTransportCandidateSelector::addCandidates( const std::vector<JingleS5BTransportPayload::Candidate>& candidates) { - foreach(JingleS5BTransportPayload::Candidate c, candidates) { + for (auto&& c : candidates) { this->candidates.push(c); } } void RemoteJingleTransportCandidateSelector::startSelectingCandidate() { tryNextCandidate(); } void RemoteJingleTransportCandidateSelector::stopSelectingCandidate() { if (s5bSession) { sessionReadyConnection.disconnect(); s5bSession->stop(); } } void RemoteJingleTransportCandidateSelector::tryNextCandidate() { if (candidates.empty()) { SWIFT_LOG(debug) << "No more candidates" << std::endl; onCandidateSelectFinished( boost::optional<JingleS5BTransportPayload::Candidate>(), std::shared_ptr<SOCKS5BytestreamClientSession>()); } else { lastCandidate = candidates.top(); candidates.pop(); SWIFT_LOG(debug) << "Trying candidate " << lastCandidate.cid << std::endl; if ((lastCandidate.type == JingleS5BTransportPayload::Candidate::DirectType && options.isDirectAllowed()) || (lastCandidate.type == JingleS5BTransportPayload::Candidate::AssistedType && options.isAssistedAllowed()) || (lastCandidate.type == JingleS5BTransportPayload::Candidate::ProxyType && options.isProxiedAllowed())) { std::shared_ptr<Connection> connection = connectionFactory->createConnection(); s5bSession = std::make_shared<SOCKS5BytestreamClientSession>( diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp index 9624d4c..90c42dd 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp @@ -1,72 +1,70 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.h> #include <memory> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/S5BProxyRequest.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/Queries/IQRouter.h> namespace Swift { SOCKS5BytestreamProxyFinder::SOCKS5BytestreamProxyFinder(const JID& service, IQRouter *iqRouter) : service(service), iqRouter(iqRouter) { } SOCKS5BytestreamProxyFinder::~SOCKS5BytestreamProxyFinder() { } void SOCKS5BytestreamProxyFinder::start() { serviceWalker = std::make_shared<DiscoServiceWalker>(service, iqRouter); serviceWalker->onServiceFound.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); serviceWalker->onWalkComplete.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleWalkEnded, this)); serviceWalker->beginWalk(); } void SOCKS5BytestreamProxyFinder::stop() { - typedef std::shared_ptr<GenericRequest<S5BProxyRequest> > S5BProxyRequestGenericRequest; - foreach (S5BProxyRequestGenericRequest requester, pendingRequests) { + for (auto&& requester : pendingRequests) { requester->onResponse.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, requester, _1, _2)); } serviceWalker->endWalk(); serviceWalker->onServiceFound.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); serviceWalker->onWalkComplete.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleWalkEnded, this)); serviceWalker.reset(); } void SOCKS5BytestreamProxyFinder::sendBytestreamQuery(const JID& jid) { S5BProxyRequest::ref proxyRequest = std::make_shared<S5BProxyRequest>(); std::shared_ptr<GenericRequest<S5BProxyRequest> > request = std::make_shared<GenericRequest<S5BProxyRequest> >(IQ::Get, jid, proxyRequest, iqRouter); request->onResponse.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, request, _1, _2)); pendingRequests.insert(request); request->send(); } void SOCKS5BytestreamProxyFinder::handleServiceFound(const JID& jid, std::shared_ptr<DiscoInfo> discoInfo) { if (discoInfo->hasFeature(DiscoInfo::Bytestream)) { sendBytestreamQuery(jid); } } void SOCKS5BytestreamProxyFinder::handleWalkEnded() { if (pendingRequests.empty()) { onProxiesFound(proxyHosts); } } void SOCKS5BytestreamProxyFinder::handleProxyResponse(std::shared_ptr<GenericRequest<S5BProxyRequest> > requester, std::shared_ptr<S5BProxyRequest> request, ErrorPayload::ref error) { diff --git a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp index 1591e24..9e214fc 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp @@ -1,38 +1,37 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> #include <memory> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> namespace Swift { SOCKS5BytestreamRegistry::SOCKS5BytestreamRegistry() { } void SOCKS5BytestreamRegistry::setHasBytestream(const std::string& destination, bool b) { if (b) { availableBytestreams.insert(destination); } else { availableBytestreams.erase(destination); } } bool SOCKS5BytestreamRegistry::hasBytestream(const std::string& destination) const { return availableBytestreams.find(destination) != availableBytestreams.end(); } std::string SOCKS5BytestreamRegistry::generateSessionID() { return idGenerator.generateID(); } } diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp index b68bd58..483ea18 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp @@ -1,69 +1,68 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> #include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> #include <Swiften/StringCodecs/Hexify.h> namespace Swift { SOCKS5BytestreamServer::SOCKS5BytestreamServer( std::shared_ptr<ConnectionServer> connectionServer, SOCKS5BytestreamRegistry* registry) : connectionServer(connectionServer), registry(registry) { } void SOCKS5BytestreamServer::start() { connectionServer->onNewConnection.connect(boost::bind(&SOCKS5BytestreamServer::handleNewConnection, this, _1)); } void SOCKS5BytestreamServer::stop() { connectionServer->onNewConnection.disconnect(boost::bind(&SOCKS5BytestreamServer::handleNewConnection, this, _1)); - foreach (std::shared_ptr<SOCKS5BytestreamServerSession> session, sessions) { + for (auto&& session : sessions) { session->onFinished.disconnect(boost::bind(&SOCKS5BytestreamServer::handleSessionFinished, this, session)); session->stop(); } sessions.clear(); } void SOCKS5BytestreamServer::handleNewConnection(std::shared_ptr<Connection> connection) { std::shared_ptr<SOCKS5BytestreamServerSession> session = std::make_shared<SOCKS5BytestreamServerSession>(connection, registry); session->onFinished.connect(boost::bind(&SOCKS5BytestreamServer::handleSessionFinished, this, session)); sessions.push_back(session); session->start(); } HostAddressPort SOCKS5BytestreamServer::getAddressPort() const { return connectionServer->getAddressPort(); } std::vector< std::shared_ptr<SOCKS5BytestreamServerSession> > SOCKS5BytestreamServer::getSessions( const std::string& streamID) const { std::vector< std::shared_ptr<SOCKS5BytestreamServerSession> > result; - foreach (std::shared_ptr<SOCKS5BytestreamServerSession> session, sessions) { + for (auto&& session : sessions) { if (session->getStreamID() == streamID) { result.push_back(session); } } return result; } void SOCKS5BytestreamServer::handleSessionFinished(std::shared_ptr<SOCKS5BytestreamServerSession> session) { sessions.erase(std::remove(sessions.begin(), sessions.end(), session), sessions.end()); session->onFinished.disconnect(boost::bind(&SOCKS5BytestreamServer::handleSessionFinished, this, session)); } } |