diff options
Diffstat (limited to 'Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp')
| -rw-r--r-- | Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp | 37 | 
1 files changed, 31 insertions, 6 deletions
| diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp index 9d7505b..78cf2e6 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp | |||
| @@ -2,16 +2,23 @@ | |||
| 2 | * Copyright (c) 2011 Tobias Markmann | 2 | * Copyright (c) 2011 Tobias Markmann | 
| 3 | * Licensed under the simplified BSD license. | 3 | * Licensed under the simplified BSD license. | 
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | 
| 5 | */ | 5 | */ | 
| 6 | 6 | ||
| 7 | /* | ||
| 8 | * Copyright (c) 2015 Isode Limited. | ||
| 9 | * All rights reserved. | ||
| 10 | * See the COPYING file for more information. | ||
| 11 | */ | ||
| 12 | |||
| 7 | #include <Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.h> | 13 | #include <Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.h> | 
| 8 | 14 | ||
| 9 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 10 | #include <boost/bind.hpp> | 15 | #include <boost/bind.hpp> | 
| 16 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 11 | 17 | ||
| 12 | #include <Swiften/Base/Log.h> | 18 | #include <Swiften/Base/Log.h> | 
| 19 | #include <Swiften/Base/foreach.h> | ||
| 13 | #include <Swiften/Elements/S5BProxyRequest.h> | 20 | #include <Swiften/Elements/S5BProxyRequest.h> | 
| 14 | #include <Swiften/Queries/GenericRequest.h> | 21 | #include <Swiften/Queries/GenericRequest.h> | 
| 15 | #include <Swiften/Queries/IQRouter.h> | 22 | #include <Swiften/Queries/IQRouter.h> | 
| 16 | 23 | ||
| 17 | namespace Swift { | 24 | namespace Swift { | 
| @@ -23,40 +30,58 @@ SOCKS5BytestreamProxyFinder::~SOCKS5BytestreamProxyFinder() { | |||
| 23 | } | 30 | } | 
| 24 | 31 | ||
| 25 | void SOCKS5BytestreamProxyFinder::start() { | 32 | void SOCKS5BytestreamProxyFinder::start() { | 
| 26 | serviceWalker = boost::make_shared<DiscoServiceWalker>(service, iqRouter); | 33 | serviceWalker = boost::make_shared<DiscoServiceWalker>(service, iqRouter); | 
| 27 | serviceWalker->onServiceFound.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); | 34 | serviceWalker->onServiceFound.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); | 
| 35 | serviceWalker->onWalkComplete.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleWalkEnded, this)); | ||
| 28 | serviceWalker->beginWalk(); | 36 | serviceWalker->beginWalk(); | 
| 29 | } | 37 | } | 
| 30 | 38 | ||
| 31 | void SOCKS5BytestreamProxyFinder::stop() { | 39 | void SOCKS5BytestreamProxyFinder::stop() { | 
| 40 | typedef boost::shared_ptr<GenericRequest<S5BProxyRequest> > S5BProxyRequestGenericRequest; | ||
| 41 | foreach (S5BProxyRequestGenericRequest requester, pendingRequests) { | ||
| 42 | requester->onResponse.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, requester, _1, _2)); | ||
| 43 | } | ||
| 44 | |||
| 32 | serviceWalker->endWalk(); | 45 | serviceWalker->endWalk(); | 
| 33 | serviceWalker->onServiceFound.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); | 46 | serviceWalker->onServiceFound.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleServiceFound, this, _1, _2)); | 
| 47 | serviceWalker->onWalkComplete.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleWalkEnded, this)); | ||
| 34 | serviceWalker.reset(); | 48 | serviceWalker.reset(); | 
| 35 | } | 49 | } | 
| 36 | 50 | ||
| 37 | void SOCKS5BytestreamProxyFinder::sendBytestreamQuery(const JID& jid) { | 51 | void SOCKS5BytestreamProxyFinder::sendBytestreamQuery(const JID& jid) { | 
| 38 | S5BProxyRequest::ref proxyRequest = boost::make_shared<S5BProxyRequest>(); | 52 | S5BProxyRequest::ref proxyRequest = boost::make_shared<S5BProxyRequest>(); | 
| 39 | boost::shared_ptr<GenericRequest<S5BProxyRequest> > request = boost::make_shared<GenericRequest<S5BProxyRequest> >(IQ::Get, jid, proxyRequest, iqRouter); | 53 | boost::shared_ptr<GenericRequest<S5BProxyRequest> > request = boost::make_shared<GenericRequest<S5BProxyRequest> >(IQ::Get, jid, proxyRequest, iqRouter); | 
| 40 | request->onResponse.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, _1, _2)); | 54 | request->onResponse.connect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, request, _1, _2)); | 
| 55 | pendingRequests.insert(request); | ||
| 41 | request->send(); | 56 | request->send(); | 
| 42 | } | 57 | } | 
| 43 | 58 | ||
| 44 | void SOCKS5BytestreamProxyFinder::handleServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> discoInfo) { | 59 | void SOCKS5BytestreamProxyFinder::handleServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> discoInfo) { | 
| 45 | if (discoInfo->hasFeature(DiscoInfo::Bytestream)) { | 60 | if (discoInfo->hasFeature(DiscoInfo::Bytestream)) { | 
| 46 | sendBytestreamQuery(jid); | 61 | sendBytestreamQuery(jid); | 
| 47 | } | 62 | } | 
| 48 | } | 63 | } | 
| 49 | 64 | ||
| 50 | void SOCKS5BytestreamProxyFinder::handleProxyResponse(boost::shared_ptr<S5BProxyRequest> request, ErrorPayload::ref error) { | 65 | void SOCKS5BytestreamProxyFinder::handleWalkEnded() { | 
| 66 | if (pendingRequests.empty()) { | ||
| 67 | onProxiesFound(proxyHosts); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | void SOCKS5BytestreamProxyFinder::handleProxyResponse(boost::shared_ptr<GenericRequest<S5BProxyRequest> > requester, boost::shared_ptr<S5BProxyRequest> request, ErrorPayload::ref error) { | ||
| 72 | requester->onResponse.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, requester, _1, _2)); | ||
| 73 | pendingRequests.erase(requester); | ||
| 51 | if (error) { | 74 | if (error) { | 
| 52 | SWIFT_LOG(debug) << "ERROR" << std::endl; | 75 | SWIFT_LOG(debug) << "ERROR" << std::endl; | 
| 53 | } else { | 76 | } else { | 
| 54 | if (request) { | 77 | if (request) { | 
| 55 | onProxyFound(request); | 78 | SWIFT_LOG(debug) << "add request" << std::endl; | 
| 56 | } else { | 79 | proxyHosts.push_back(request); | 
| 57 | //assert(false); | ||
| 58 | } | 80 | } | 
| 59 | } | 81 | } | 
| 82 | if (pendingRequests.empty() && !serviceWalker->isActive()) { | ||
| 83 | onProxiesFound(proxyHosts); | ||
| 84 | } | ||
| 60 | } | 85 | } | 
| 61 | 86 | ||
| 62 | } | 87 | } | 
 Swift
 Swift