QXmpp: QXmppTransferManager.h Source File

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
QXmppTransferManager.h
1// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPTRANSFERMANAGER_H
6#define QXMPPTRANSFERMANAGER_H
7
8#include "QXmppClientExtension.h"
9
10#include <QDateTime>
11#include <QSharedData>
12#include <QUrl>
13#include <QVariant>
14
15class QTcpSocket;
16class QXmppByteStreamIq;
17class QXmppIbbCloseIq;
18class QXmppIbbDataIq;
19class QXmppIbbOpenIq;
20class QXmppIq;
21class QXmppStreamInitiationIq;
22class QXmppTransferFileInfoPrivate;
23class QXmppTransferJobPrivate;
24class QXmppTransferManager;
25class QXmppTransferManagerPrivate;
26
27 class QXMPP_EXPORT QXmppTransferFileInfo
28{
29public:
30 QXmppTransferFileInfo();
31 QXmppTransferFileInfo(const QXmppTransferFileInfo &other);
32 ~QXmppTransferFileInfo();
33
34 QDateTime date() const;
35 void setDate(const QDateTime &date);
36
37 QByteArray hash() const;
38 void setHash(const QByteArray &hash);
39
40 QString name() const;
41 void setName(const QString &name);
42
43 QString description() const;
44 void setDescription(const QString &description);
45
46 qint64 size() const;
47 void setSize(qint64 size);
48
49 bool isNull() const;
50 QXmppTransferFileInfo &operator=(const QXmppTransferFileInfo &other);
51 bool operator==(const QXmppTransferFileInfo &other) const;
52
54 static constexpr std::tuple XmlTag = { u"file", QXmpp::Private::ns_stream_initiation_file_transfer };
55 void parse(const QDomElement &element);
56 void toXml(QXmlStreamWriter *writer) const;
58
59private:
60 QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
61};
62
63 class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
64{
65 Q_OBJECT
66 Q_FLAGS(Method Methods)
68 Q_PROPERTY(Direction direction READ direction CONSTANT)
70 Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
72 Q_PROPERTY(QString jid READ jid CONSTANT)
74 Q_PROPERTY(Method method READ method CONSTANT)
76 Q_PROPERTY(State state READ state NOTIFY stateChanged)
77
79 Q_PROPERTY(QString fileName READ fileName CONSTANT)
81 Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
82
83public:
85 enum Direction {
86 IncomingDirection,
87 OutgoingDirection
88 };
89 Q_ENUM(Direction)
90
91
92 enum Error {
93 NoError = 0,
94 AbortError,
95 FileAccessError,
96 FileCorruptError,
97 ProtocolError
98 };
99 Q_ENUM(Error)
100
101
102 enum Method {
103 NoMethod = 0,
104 InBandMethod = 1,
105 SocksMethod = 2,
106 AnyMethod = 3
107 };
108 Q_ENUM(Method)
109 Q_DECLARE_FLAGS(Methods, Method)
110
111
112 enum State {
113 OfferState = 0,
114 StartState = 1,
115 TransferState = 2,
116 FinishedState = 3
117 };
118 Q_ENUM(State)
119
120 ~QXmppTransferJob() override;
121
122 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
124 QXmppTransferJob::Direction direction() const;
126 QString jid() const;
128 QXmppTransferJob::Method method() const;
130 QXmppTransferJob::State state() const;
131
132 QXmppTransferJob::Error error() const;
133 QString sid() const;
134 qint64 speed() const;
135
136 // XEP-0096 : File transfer
137 QXmppTransferFileInfo fileInfo() const;
138 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
140 QUrl localFileUrl() const;
141 void setLocalFileUrl(const QUrl &localFileUrl);
142
144 QDateTime fileDate() const;
145 QByteArray fileHash() const;
146 QString fileName() const;
147 qint64 fileSize() const;
149
152 Q_SIGNAL void error(QXmppTransferJob::Error error);
153
161 Q_SIGNAL void finished();
162
164 Q_SIGNAL void localFileUrlChanged(const QUrl &localFileUrl);
165
167 Q_SIGNAL void progress(qint64 done, qint64 total);
168
170 Q_SIGNAL void stateChanged(QXmppTransferJob::State state);
171
172 Q_SLOT void abort();
173 Q_SLOT void accept(const QString &filePath);
174 Q_SLOT void accept(QIODevice *output);
175
176private:
177 QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QXmppClient *client, QObject *parent);
178
179 Q_SLOT void _q_terminated();
180
181 void setState(QXmppTransferJob::State state);
182 void terminate(QXmppTransferJob::Error error);
183
184 const std::unique_ptr<QXmppTransferJobPrivate> d;
185 friend class QXmppTransferManager;
186 friend class QXmppTransferManagerPrivate;
187 friend class QXmppTransferIncomingJob;
188 friend class QXmppTransferOutgoingJob;
189};
190
191 class QXMPP_EXPORT QXmppTransferManager : public QXmppClientExtension
192{
193 Q_OBJECT
194
196 Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
198 Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
200 Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
201
202public:
203 QXmppTransferManager();
204 ~QXmppTransferManager() override;
205
206 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
208 QString proxy() const;
209 void setProxy(const QString &proxyJid);
210
211 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
214 bool proxyOnly() const;
215 void setProxyOnly(bool proxyOnly);
216
217 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
221 QXmppTransferJob::Methods supportedMethods() const;
222 void setSupportedMethods(QXmppTransferJob::Methods methods);
223
225 QStringList discoveryFeatures() const override;
226 bool handleStanza(const QDomElement &element) override;
228
233 Q_SIGNAL void fileReceived(QXmppTransferJob *job);
234
236 Q_SIGNAL void jobStarted(QXmppTransferJob *job);
237
241 Q_SIGNAL void jobFinished(QXmppTransferJob *job);
242
243 Q_SLOT QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &description = QString());
244 Q_SLOT QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
245
246protected:
248 void onRegistered(QXmppClient *client) override;
249 void onUnregistered(QXmppClient *client) override;
251
252private:
253 Q_SLOT void _q_iqReceived(const QXmppIq &);
254 Q_SLOT void _q_jobDestroyed(QObject *object);
255 Q_SLOT void _q_jobError(QXmppTransferJob::Error error);
256 Q_SLOT void _q_jobFinished();
257 Q_SLOT void _q_jobStateChanged(QXmppTransferJob::State state);
258 Q_SLOT void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
259
260 void byteStreamIqReceived(const QXmppByteStreamIq &);
261 void byteStreamResponseReceived(const QXmppIq &);
262 void byteStreamResultReceived(const QXmppByteStreamIq &);
263 void byteStreamSetReceived(const QXmppByteStreamIq &);
264 void ibbCloseIqReceived(const QXmppIbbCloseIq &);
265 void ibbDataIqReceived(const QXmppIbbDataIq &);
266 void ibbOpenIqReceived(const QXmppIbbOpenIq &);
267 void ibbResponseReceived(const QXmppIq &);
268 void streamInitiationIqReceived(const QXmppStreamInitiationIq &);
269 void streamInitiationResultReceived(const QXmppStreamInitiationIq &);
270 void streamInitiationSetReceived(const QXmppStreamInitiationIq &);
271 void socksServerSendOffer(QXmppTransferJob *job);
272
273 const std::unique_ptr<QXmppTransferManagerPrivate> d;
274
275 friend class QXmppTransferManagerPrivate;
276};
277
278Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
279
280#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