diff options
author | Tobias Markmann <tm@ayena.de> | 2016-04-21 09:02:07 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-11-10 11:09:16 (GMT) |
commit | d2ba1ab8a36333523bf794c23226bd044e1717c2 (patch) | |
tree | 737ac14bc1dfcec4b80192ea23e7b0e860a2f8d3 /Swiften/FileTransfer | |
parent | 41c771ec02682c2b344263d29f68eb6452c42dbe (diff) | |
download | swift-d2ba1ab8a36333523bf794c23226bd044e1717c2.zip swift-d2ba1ab8a36333523bf794c23226bd044e1717c2.tar.bz2 |
Use FeatureOracle to detect file-transfer support in roster
The FeatureOracle provides tri-state feature lookup
functionality for bare JIDs. It returns Yes if a feature is
supported by all resources of the bare JID, Maybe if some
support it, and No if none of the resources support it.
If passed a full JID, it returns the specific features supported
by that end-point.
Sending a file to a bare JID, will send a file to the resource
of the bare JID with the highest availability by presence, show
status and priority and which supports the features required
for a Jingle file-transfer.
Test-Information:
Added unit test verifying new behavior.
All tests pass on OS X 10.11.6. Added new unit tests for
FeatureOracle.
Manually verified that the roster and chat window both use
the same mechanism to detect support for file-transfers.
Manually verified that file-transfers via the contact list
goes to already bound full JIDs if there is an existing
ChatController.
Change-Id: I0175ac42ecb73f1d54f9c96ffbba773eb5e24296
Diffstat (limited to 'Swiften/FileTransfer')
-rw-r--r-- | Swiften/FileTransfer/FileTransferManager.cpp | 15 | ||||
-rw-r--r-- | Swiften/FileTransfer/FileTransferManager.h | 2 | ||||
-rw-r--r-- | Swiften/FileTransfer/FileTransferManagerImpl.cpp | 31 |
3 files changed, 11 insertions, 37 deletions
diff --git a/Swiften/FileTransfer/FileTransferManager.cpp b/Swiften/FileTransfer/FileTransferManager.cpp index 94f4ab7..a5d7313 100644 --- a/Swiften/FileTransfer/FileTransferManager.cpp +++ b/Swiften/FileTransfer/FileTransferManager.cpp @@ -4,6 +4,12 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include <Swiften/FileTransfer/FileTransferManager.h> namespace Swift { @@ -11,13 +17,4 @@ namespace Swift { FileTransferManager::~FileTransferManager() { } -bool FileTransferManager::isSupportedBy(const DiscoInfo::ref info) { - if (info) { - return info->hasFeature(DiscoInfo::JingleFeature) - && info->hasFeature(DiscoInfo::JingleFTFeature) - && (info->hasFeature(DiscoInfo::JingleTransportsIBBFeature) || info->hasFeature(DiscoInfo::JingleTransportsS5BFeature)); - } - return false; -} - } diff --git a/Swiften/FileTransfer/FileTransferManager.h b/Swiften/FileTransfer/FileTransferManager.h index e315c67..07cfc90 100644 --- a/Swiften/FileTransfer/FileTransferManager.h +++ b/Swiften/FileTransfer/FileTransferManager.h @@ -47,8 +47,6 @@ namespace Swift { std::shared_ptr<ReadBytestream> bytestream, const FileTransferOptions& = FileTransferOptions()) = 0; - static bool isSupportedBy(const DiscoInfo::ref info); - boost::signals2::signal<void (IncomingFileTransfer::ref)> onIncomingFileTransfer; }; } diff --git a/Swiften/FileTransfer/FileTransferManagerImpl.cpp b/Swiften/FileTransfer/FileTransferManagerImpl.cpp index d449179..05dd3bb 100644 --- a/Swiften/FileTransfer/FileTransferManagerImpl.cpp +++ b/Swiften/FileTransfer/FileTransferManagerImpl.cpp @@ -19,8 +19,8 @@ #include <Swiften/Base/BoostFilesystemVersion.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/Path.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Disco/EntityCapsProvider.h> +#include <Swiften/Disco/FeatureOracle.h> #include <Swiften/Elements/JingleFileTransferFileInfo.h> #include <Swiften/Elements/Presence.h> #include <Swiften/FileTransfer/DefaultFileTransferTransporterFactory.h> @@ -99,28 +99,6 @@ void FileTransferManagerImpl::stop() { s5bServerManager->stop(); } -boost::optional<JID> FileTransferManagerImpl::highestPriorityJIDSupportingFileTransfer(const JID& bareJID) { - JID fullReceipientJID; - int priority = INT_MIN; - - //getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Isode Limited. @ 11:11 - std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID); - - //iterate over them - foreach(Presence::ref pres, presences) { - if (pres->getPriority() > priority) { - // look up caps from the jid - DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom()); - if (isSupportedBy(info)) { - priority = pres->getPriority(); - fullReceipientJID = pres->getFrom(); - } - } - } - - return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>(); -} - OutgoingFileTransfer::ref FileTransferManagerImpl::createOutgoingFileTransfer( const JID& to, const boost::filesystem::path& filepath, @@ -155,9 +133,10 @@ OutgoingFileTransfer::ref FileTransferManagerImpl::createOutgoingFileTransfer( JID receipient = to; if(receipient.isBare()) { - boost::optional<JID> fullJID = highestPriorityJIDSupportingFileTransfer(receipient); - if (fullJID.is_initialized()) { - receipient = fullJID.get(); + auto featureOracle = FeatureOracle(capsProvider, presenceOracle); + JID fullJID = featureOracle.getMostAvailableClientForFileTrasfer(receipient); + if (!fullJID.toString().empty()) { + receipient = fullJID; } else { return OutgoingFileTransfer::ref(); } |