diff options
Diffstat (limited to 'Swiften/Examples/SendFile/ReceiveFile.cpp')
-rw-r--r-- | Swiften/Examples/SendFile/ReceiveFile.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp index effa1b7..f80f03a 100644 --- a/Swiften/Examples/SendFile/ReceiveFile.cpp +++ b/Swiften/Examples/SendFile/ReceiveFile.cpp @@ -12,12 +12,18 @@ #include <Swiften/Elements/Presence.h> #include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> +#include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Network/BoostNetworkFactories.h> #include <Swiften/EventLoop/SimpleEventLoop.h> #include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/Disco/ClientDiscoManager.h> #include <Swiften/FileTransfer/IncomingFileTransferManager.h> #include <Swiften/FileTransfer/FileWriteBytestream.h> #include <Swiften/Jingle/JingleSessionManager.h> +#include <Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGeneratorFactory.h> +#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> +#include <Swiften/FileTransfer/FileTransferManager.h> using namespace Swift; @@ -26,19 +32,20 @@ BoostNetworkFactories networkFactories(&eventLoop); int exitCode = 2; +static const std::string CLIENT_NAME = "Swiften FT Test"; +static const std::string CLIENT_NODE = "http://swift.im"; + class FileReceiver { public: FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password), jingleSessionManager(NULL), incomingFileTransferManager(NULL) { client = new Swift::Client(jid, password, &networkFactories); client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this)); client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); - //tracer = new ClientXMLTracer(client); + tracer = new ClientXMLTracer(client); } ~FileReceiver() { - delete incomingFileTransferManager; - delete jingleSessionManager; - //delete tracer; + delete tracer; client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this)); delete client; @@ -57,13 +64,24 @@ class FileReceiver { private: void handleConnected() { - client->sendPresence(Presence::create()); - jingleSessionManager = new JingleSessionManager(client->getIQRouter()); - incomingFileTransferManager = new IncomingFileTransferManager(jingleSessionManager, client->getIQRouter()); - incomingFileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1)); + Swift::logging = true; + client->getFileTransferManager()->startListeningOnPort(9999); + client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1)); + + DiscoInfo discoInfo; + discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc")); + discoInfo.addFeature(DiscoInfo::JingleFeature); + discoInfo.addFeature(DiscoInfo::JingleFTFeature); + discoInfo.addFeature(DiscoInfo::Bytestream); + discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature); + discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature); + client->getDiscoManager()->setCapsNode(CLIENT_NODE); + client->getDiscoManager()->setDiscoInfo(discoInfo); + client->getPresenceSender()->sendPresence(Presence::create()); } void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) { + SWIFT_LOG(debug) << "foo" << std::endl; incomingFileTransfers.push_back(transfer); transfer->accept(boost::make_shared<FileWriteBytestream>("out")); //transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1)); @@ -100,6 +118,9 @@ class FileReceiver { JingleSessionManager* jingleSessionManager; IncomingFileTransferManager* incomingFileTransferManager; std::vector<IncomingFileTransfer::ref> incomingFileTransfers; + DefaultLocalJingleTransportCandidateGeneratorFactory *localFactory; + DefaultRemoteJingleTransportCandidateSelectorFactory *remoteFactory; + SOCKS5BytestreamRegistry* bytestreamRegistry; }; |