QXmpp  Version: 1.15.1
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 
15 class QTcpSocket;
16 class QXmppByteStreamIq;
17 class QXmppIbbCloseIq;
18 class QXmppIbbDataIq;
19 class QXmppIbbOpenIq;
20 class QXmppIq;
21 class QXmppStreamInitiationIq;
22 class QXmppTransferFileInfoPrivate;
23 class QXmppTransferJobPrivate;
25 class QXmppTransferManagerPrivate;
26 
27 class QXMPP_EXPORT QXmppTransferFileInfo
28 {
29 public:
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 
59 private:
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 
83 public:
85  enum Direction {
87  OutgoingDirection
88  };
89  Q_ENUM(Direction)
90 
91 
92  enum Error {
93  NoError = 0,
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 
176 private:
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 
202 public:
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 
246 protected:
248  void onRegistered(QXmppClient *client) override;
249  void onUnregistered(QXmppClient *client) override;
251 
252 private:
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 
278 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
279 
280 #endif
Error
This enum is used to describe the type of error encountered by a transfer job.
Definition: QXmppTransferManager.h:92
The file transfer was aborted.
Definition: QXmppTransferManager.h:94
Definition: QXmppTask.h:646
Definition: QXmppIbbIq.h:11
Definition: QXmppTransferManager.h:63
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:108
An error was encountered trying to access a local file.
Definition: QXmppTransferManager.h:95
Definition: QXmppTransferManager.h:191
State
This enum is used to describe the state of a transfer job.
Definition: QXmppTransferManager.h:112
Definition: QXmppIbbIq.h:37
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:22
The file is corrupt: the file size or hash do not match.
Definition: QXmppTransferManager.h:96
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:31
Definition: QXmppByteStreamIq.h:13
The file is being received.
Definition: QXmppTransferManager.h:86
Method
This enum is used to describe a transfer method.
Definition: QXmppTransferManager.h:102
Definition: QXmppTransferManager.h:27
Main class for starting and managing connections to XMPP servers.
Definition: QXmppClient.h:61
Direction
This enum is used to describe the direction of a transfer job.
Definition: QXmppTransferManager.h:85