Loading...
Searching...
No Matches
QXmppTransferManager.h
// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPTRANSFERMANAGER_H
#define QXMPPTRANSFERMANAGER_H
#include "QXmppClientExtension.h"
#include <QDateTime>
#include <QSharedData>
#include <QUrl>
#include <QVariant>
class QTcpSocket;
class QXmppByteStreamIq;
class QXmppIbbCloseIq;
class QXmppIbbDataIq;
class QXmppIbbOpenIq;
class QXmppIq;
class QXmppStreamInitiationIq;
class QXmppTransferFileInfoPrivate;
class QXmppTransferJobPrivate;
class QXmppTransferManager;
class QXmppTransferManagerPrivate;
class QXMPP_EXPORT QXmppTransferFileInfo
{
public:
QXmppTransferFileInfo();
QXmppTransferFileInfo(const QXmppTransferFileInfo &other);
~QXmppTransferFileInfo();
QDateTime date() const;
void setDate(const QDateTime &date);
QByteArray hash() const;
void setHash(const QByteArray &hash);
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &description);
qint64 size() const;
void setSize(qint64 size);
bool isNull() const;
QXmppTransferFileInfo &operator=(const QXmppTransferFileInfo &other);
bool operator==(const QXmppTransferFileInfo &other) const;
static constexpr std::tuple XmlTag = { u"file", QXmpp::Private::ns_stream_initiation_file_transfer };
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
private:
QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
};
class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
{
Q_OBJECT
Q_FLAGS(Method Methods)
Q_PROPERTY(Direction direction READ direction CONSTANT)
Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
Q_PROPERTY(QString jid READ jid CONSTANT)
Q_PROPERTY(Method method READ method CONSTANT)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QString fileName READ fileName CONSTANT)
Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
public:
enum Direction {
IncomingDirection,
OutgoingDirection
};
Q_ENUM(Direction)
enum Error {
NoError = 0,
AbortError,
FileAccessError,
FileCorruptError,
ProtocolError
};
Q_ENUM(Error)
enum Method {
NoMethod = 0,
InBandMethod = 1,
SocksMethod = 2,
AnyMethod = 3
};
Q_ENUM(Method)
Q_DECLARE_FLAGS(Methods, Method)
enum State {
OfferState = 0,
StartState = 1,
TransferState = 2,
FinishedState = 3
};
Q_ENUM(State)
~QXmppTransferJob() override;
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QXmppTransferJob::Direction direction() const;
QString jid() const;
QXmppTransferJob::Method method() const;
QXmppTransferJob::State state() const;
QXmppTransferJob::Error error() const;
QString sid() const;
qint64 speed() const;
// XEP-0096 : File transfer
QXmppTransferFileInfo fileInfo() const;
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QUrl localFileUrl() const;
void setLocalFileUrl(const QUrl &localFileUrl);
QDateTime fileDate() const;
QByteArray fileHash() const;
QString fileName() const;
qint64 fileSize() const;
Q_SIGNAL void error(QXmppTransferJob::Error error);
Q_SIGNAL void finished();
Q_SIGNAL void localFileUrlChanged(const QUrl &localFileUrl);
Q_SIGNAL void progress(qint64 done, qint64 total);
Q_SIGNAL void stateChanged(QXmppTransferJob::State state);
Q_SLOT void abort();
Q_SLOT void accept(const QString &filePath);
Q_SLOT void accept(QIODevice *output);
private:
QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QXmppClient *client, QObject *parent);
Q_SLOT void _q_terminated();
void setState(QXmppTransferJob::State state);
void terminate(QXmppTransferJob::Error error);
const std::unique_ptr<QXmppTransferJobPrivate> d;
friend class QXmppTransferManager;
friend class QXmppTransferManagerPrivate;
friend class QXmppTransferIncomingJob;
friend class QXmppTransferOutgoingJob;
};
class QXMPP_EXPORT QXmppTransferManager : public QXmppClientExtension
{
Q_OBJECT
Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
public:
QXmppTransferManager();
~QXmppTransferManager() override;
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QString proxy() const;
void setProxy(const QString &proxyJid);
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
bool proxyOnly() const;
void setProxyOnly(bool proxyOnly);
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QXmppTransferJob::Methods supportedMethods() const;
void setSupportedMethods(QXmppTransferJob::Methods methods);
QStringList discoveryFeatures() const override;
bool handleStanza(const QDomElement &element) override;
Q_SIGNAL void fileReceived(QXmppTransferJob *job);
Q_SIGNAL void jobStarted(QXmppTransferJob *job);
Q_SIGNAL void jobFinished(QXmppTransferJob *job);
Q_SLOT QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &description = QString());
Q_SLOT QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
protected:
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;
private:
Q_SLOT void _q_iqReceived(const QXmppIq &);
Q_SLOT void _q_jobDestroyed(QObject *object);
Q_SLOT void _q_jobError(QXmppTransferJob::Error error);
Q_SLOT void _q_jobFinished();
Q_SLOT void _q_jobStateChanged(QXmppTransferJob::State state);
Q_SLOT void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
void byteStreamIqReceived(const QXmppByteStreamIq &);
void byteStreamResponseReceived(const QXmppIq &);
void byteStreamResultReceived(const QXmppByteStreamIq &);
void byteStreamSetReceived(const QXmppByteStreamIq &);
void ibbCloseIqReceived(const QXmppIbbCloseIq &);
void ibbDataIqReceived(const QXmppIbbDataIq &);
void ibbOpenIqReceived(const QXmppIbbOpenIq &);
void ibbResponseReceived(const QXmppIq &);
void streamInitiationIqReceived(const QXmppStreamInitiationIq &);
void streamInitiationResultReceived(const QXmppStreamInitiationIq &);
void streamInitiationSetReceived(const QXmppStreamInitiationIq &);
void socksServerSendOffer(QXmppTransferJob *job);
const std::unique_ptr<QXmppTransferManagerPrivate> d;
friend class QXmppTransferManagerPrivate;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
#endif
QXmppByteStreamIq
Definition QXmppByteStreamIq.h:14
QXmppClientExtension::discoveryFeatures
virtual QStringList discoveryFeatures() const
Definition QXmppClientExtension.cpp:22
QXmppClientExtension::onUnregistered
virtual void onUnregistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:95
QXmppClientExtension::onRegistered
virtual void onRegistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:85
QXmppClientExtension::client
QXmppClient * client() const
Definition QXmppClientExtension.cpp:57
QXmppClientExtension::QXmppClientExtension
QXmppClientExtension()
Definition QXmppClientExtension.cpp:12
QXmppClientExtension::handleStanza
virtual bool handleStanza(const QDomElement &stanza)
You need to implement this method to process incoming XMPP stanzas.
Definition client/compat/removed_api.cpp:44
QXmppClient
Main class for starting and managing connections to XMPP servers.
Definition QXmppClient.h:62
QXmppIbbCloseIq
Definition QXmppIbbIq.h:38
QXmppIbbOpenIq
Definition QXmppIbbIq.h:12
QXmppIq
The QXmppIq class is the base class for all IQs.
Definition QXmppIq.h:23
QXmppLoggable::QXmppLoggable
QXmppLoggable(QObject *parent=nullptr)
Definition QXmppLogger.cpp:57
QXmppTransferFileInfo
Definition QXmppTransferManager.h:28
QXmppTransferFileInfo::date
QDateTime date() const
Definition QXmppTransferManager.cpp:77
QXmppTransferFileInfo::setHash
void setHash(const QByteArray &hash)
Definition QXmppTransferManager.cpp:101
QXmppTransferFileInfo::setName
void setName(const QString &name)
Definition QXmppTransferManager.cpp:117
QXmppTransferFileInfo::isNull
bool isNull() const
Definition QXmppTransferManager.cpp:157
QXmppTransferFileInfo::setSize
void setSize(qint64 size)
Definition QXmppTransferManager.cpp:149
QXmppTransferFileInfo::QXmppTransferFileInfo
QXmppTransferFileInfo(const QXmppTransferFileInfo &other)
Default copy-constructor.
QXmppTransferFileInfo::operator=
QXmppTransferFileInfo & operator=(const QXmppTransferFileInfo &other)
Default assignment operator.
QXmppTransferFileInfo::setDescription
void setDescription(const QString &description)
Definition QXmppTransferManager.cpp:133
QXmppTransferFileInfo::operator==
bool operator==(const QXmppTransferFileInfo &other) const
Definition QXmppTransferManager.cpp:169
QXmppTransferFileInfo::name
QString name() const
Definition QXmppTransferManager.cpp:109
QXmppTransferFileInfo::size
qint64 size() const
Definition QXmppTransferManager.cpp:141
QXmppTransferFileInfo::hash
QByteArray hash() const
Definition QXmppTransferManager.cpp:93
QXmppTransferFileInfo::description
QString description() const
Definition QXmppTransferManager.cpp:125
QXmppTransferFileInfo::setDate
void setDate(const QDateTime &date)
Definition QXmppTransferManager.cpp:85
QXmppTransferJob
Definition QXmppTransferManager.h:64
QXmppTransferJob::fileName
QString fileName
The name of the file.
Definition QXmppTransferManager.h:79
QXmppTransferJob::error
QXmppTransferJob::Error error() const
Definition QXmppTransferManager.cpp:314
QXmppTransferJob::abort
Q_SLOT void abort()
Definition QXmppTransferManager.cpp:271
QXmppTransferJob::progress
Q_SIGNAL void progress(qint64 done, qint64 total)
This signal is emitted to indicate the progress of this transfer job.
QXmppTransferJob::finished
Q_SIGNAL void finished()
QXmppTransferJob::method
Method method
The job's transfer method.
Definition QXmppTransferManager.h:74
QXmppTransferJob::setLocalFileUrl
void setLocalFileUrl(const QUrl &localFileUrl)
Definition QXmppTransferManager.cpp:335
QXmppTransferJob::stateChanged
Q_SIGNAL void stateChanged(QXmppTransferJob::State state)
This signal is emitted when the transfer job changes state.
QXmppTransferJob::fileSize
qint64 fileSize
The size of the file.
Definition QXmppTransferManager.h:81
QXmppTransferJob::Method
Method
This enum is used to describe a transfer method.
Definition QXmppTransferManager.h:102
QXmppTransferJob::AnyMethod
@ AnyMethod
Any supported transfer method.
Definition QXmppTransferManager.h:106
QXmppTransferJob::NoMethod
@ NoMethod
No transfer method.
Definition QXmppTransferManager.h:103
QXmppTransferJob::SocksMethod
@ SocksMethod
XEP-0065: SOCKS5 Bytestreams
Definition QXmppTransferManager.h:105
QXmppTransferJob::InBandMethod
@ InBandMethod
XEP-0047: In-Band Bytestreams
Definition QXmppTransferManager.h:104
QXmppTransferJob::Direction
Direction
This enum is used to describe the direction of a transfer job.
Definition QXmppTransferManager.h:85
QXmppTransferJob::OutgoingDirection
@ OutgoingDirection
The file is being sent.
Definition QXmppTransferManager.h:87
QXmppTransferJob::IncomingDirection
@ IncomingDirection
The file is being received.
Definition QXmppTransferManager.h:86
QXmppTransferJob::jid
QString jid
The remote party's JID.
Definition QXmppTransferManager.h:72
QXmppTransferJob::State
State
This enum is used to describe the state of a transfer job.
Definition QXmppTransferManager.h:112
QXmppTransferJob::OfferState
@ OfferState
The transfer is being offered to the remote party.
Definition QXmppTransferManager.h:113
QXmppTransferJob::FinishedState
@ FinishedState
The transfer is finished.
Definition QXmppTransferManager.h:116
QXmppTransferJob::StartState
@ StartState
The transfer is being connected.
Definition QXmppTransferManager.h:114
QXmppTransferJob::TransferState
@ TransferState
The transfer is ongoing.
Definition QXmppTransferManager.h:115
QXmppTransferJob::localFileUrlChanged
Q_SIGNAL void localFileUrlChanged(const QUrl &localFileUrl)
This signal is emitted when the local file URL changes.
QXmppTransferJob::localFileUrl
QUrl localFileUrl
The local file URL.
Definition QXmppTransferManager.h:70
QXmppTransferJob::Error
Error
This enum is used to describe the type of error encountered by a transfer job.
Definition QXmppTransferManager.h:92
QXmppTransferJob::AbortError
@ AbortError
The file transfer was aborted.
Definition QXmppTransferManager.h:94
QXmppTransferJob::FileAccessError
@ FileAccessError
An error was encountered trying to access a local file.
Definition QXmppTransferManager.h:95
QXmppTransferJob::ProtocolError
@ ProtocolError
An error was encountered in the file transfer protocol.
Definition QXmppTransferManager.h:97
QXmppTransferJob::FileCorruptError
@ FileCorruptError
The file is corrupt: the file size or hash do not match.
Definition QXmppTransferManager.h:96
QXmppTransferJob::NoError
@ NoError
No error occurred.
Definition QXmppTransferManager.h:93
QXmppTransferJob::error
Q_SIGNAL void error(QXmppTransferJob::Error error)
QXmppTransferJob::direction
Direction direction
The job's transfer direction.
Definition QXmppTransferManager.h:68
QXmppTransferJob::accept
Q_SLOT void accept(const QString &filePath)
Definition QXmppTransferManager.cpp:279
QXmppTransferJob::state
State state
The job's state.
Definition QXmppTransferManager.h:76
QXmppTransferManager
Definition QXmppTransferManager.h:192
QXmppTransferManager::setSupportedMethods
void setSupportedMethods(QXmppTransferJob::Methods methods)
Definition QXmppTransferManager.cpp:1610
QXmppTransferManager::sendFile
Q_SLOT QXmppTransferJob * sendFile(const QString &jid, const QString &filePath, const QString &description=QString())
Definition QXmppTransferManager.cpp:1247
QXmppTransferManager::proxy
QString proxy
The JID of the bytestream proxy to use for outgoing transfers.
Definition QXmppTransferManager.h:196
QXmppTransferManager::setProxyOnly
void setProxyOnly(bool proxyOnly)
Definition QXmppTransferManager.cpp:1593
QXmppTransferManager::jobFinished
Q_SIGNAL void jobFinished(QXmppTransferJob *job)
QXmppTransferManager::QXmppTransferManager
QXmppTransferManager()
Definition QXmppTransferManager.cpp:781
QXmppTransferManager::fileReceived
Q_SIGNAL void fileReceived(QXmppTransferJob *job)
QXmppTransferManager::proxyOnly
bool proxyOnly
Whether the proxy will systematically be used for outgoing SOCKS5 bytestream transfers.
Definition QXmppTransferManager.h:198
QXmppTransferManager::setProxy
void setProxy(const QString &proxyJid)
Definition QXmppTransferManager.cpp:1576
QXmppTransferManager::jobStarted
Q_SIGNAL void jobStarted(QXmppTransferJob *job)
This signal is emitted whenever a transfer job is started.
QXmppTransferManager::supportedMethods
QXmppTransferJob::Methods supportedMethods
The supported stream methods.
Definition QXmppTransferManager.h:200