QXmpp: QXmppUploadRequestManager Class Reference

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
QXmppUploadRequestManager Class Reference
Managers

The QXmppUploadRequestManager implements the core of XEP-0369: HTTP File Upload. More...

`#include <QXmppUploadRequestManager.h>`

Inheritance diagram for QXmppUploadRequestManager:

## Public Types
using | SlotResult = std::variant<QXmppHttpUploadSlotIq, QXmppError>

## Public Member Functions
QString | requestUploadSlot (const QFileInfo &file, const QString &uploadService=QString())
QString | requestUploadSlot (const QFileInfo &file, const QString &customFileName, const QString &uploadService=QString())
QString | requestUploadSlot (const QString &fileName, qint64 fileSize, const QMimeType &mimeType, const QString &uploadService=QString())
auto | requestSlot (const QFileInfo &file, const QString &uploadService={}) -> QXmppTask< SlotResult >
auto | requestSlot (const QFileInfo &file, const QString &customFileName, const QString &uploadService={}) -> QXmppTask< SlotResult >
auto | requestSlot (const QString &fileName, qint64 fileSize, const QMimeType &mimeType, const QString &uploadService={}) -> QXmppTask< SlotResult >
bool | serviceFound () const
| Returns true if an HTTP File Upload service has been discovered.
QVector< QXmppUploadService > | uploadServices () const
| Returns all discovered HTTP File Upload services.
bool | handleStanza (const QDomElement &stanza) override
| You need to implement this method to process incoming XMPP stanzas.
Q_SIGNAL void | slotReceived (const QXmppHttpUploadSlotIq &slot)
| Emitted when an upload slot was received.
Q_SIGNAL void | requestFailed (const QXmppHttpUploadRequestIq &request)
Q_SIGNAL void | serviceFoundChanged ()
| Emitted when the first upload service has been found.
Public Member Functions inherited from QXmppClientExtension
| QXmppClientExtension ()
virtual QStringList | discoveryFeatures () const
virtual QList< QXmppDiscoIdentity > | discoveryIdentities () const
virtual bool | handleStanza (const QDomElement &stanza, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
| You need to implement this method to process incoming XMPP stanzas.
Public Member Functions inherited from QXmppLoggable
| QXmppLoggable (QObject *parent=nullptr)
Q_SIGNAL void | setGauge (const QString &gauge, double value)
| Sets the given gauge to value.
Q_SIGNAL void | logMessage (QXmppLogger::MessageType type, const QString &msg)
| This signal is emitted to send logging messages.
Q_SIGNAL void | updateCounter (const QString &counter, qint64 amount=1)
| Updates the given counter by amount.

## Protected Member Functions
void | onRegistered (QXmppClient *client) override
void | onUnregistered (QXmppClient *client) override
Protected Member Functions inherited from QXmppClientExtension
QXmppClient * | client () const
virtual void | setClient (QXmppClient *client)
void | injectIq (const QDomElement &element, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
bool | injectMessage (QXmppMessage &&message)
Protected Member Functions inherited from QXmppLoggable
void | debug (const QString &message)
| Logs a debugging message.
void | info (const QString &message)
| Logs an informational message.
void | warning (const QString &message)
| Logs a warning message.
void | logReceived (const QString &message)
| Logs a received packet.
void | logSent (const QString &message)
| Logs a sent packet.

## Detailed Description

The QXmppUploadRequestManager implements the core of XEP-0369: HTTP File Upload.

It handles the discovery of QXmppUploadServices and can send upload requests and outputs the upload slots. It doesn't do the actual upload via. HTTP.

To make use of this manager, you need to instantiate it and load it into the QXmppClient instance as follows:

auto *manager = new QXmppUploadRequestManager;
client->addExtension(manager);
QXmppClientExtension::client
QXmppClient * client() const
Definition QXmppClientExtension.cpp:57

Apart from that, you also need to discover HTTP File Upload service(s) by requesting the Service Discovery info for each Service Discovery item of the server. The QXmppUploadManager will then automatically recognize upload services and add them to the list of discovered services `uploadServices()`.

Keep in mind that theoretically any XMPP entity could promote to be an upload service and so is recognized by this manager. A potential attacker could exploit this vulnerability, so the client could be uploading files to the attacker (e.g. a normal user JID) instead of the own server.

As soon as at least one upload service has been discovered, you can start to request upload slots by using `requestUploadSlot()`. Alternatively you can provide the JID of the upload service which should be used for uploading.

Since
  QXmpp 1.1

## Member Typedef Documentation

## ◆ SlotResult

using QXmppUploadRequestManager::SlotResult = std::variant<QXmppHttpUploadSlotIq, QXmppError>

Contains the requested upload slot from the service or a QXmppStanza::Error in case the request failed.

Since
  QXmpp 1.5

## Member Function Documentation

## ◆ handleStanza()

bool QXmppUploadRequestManager::handleStanza | ( | const QDomElement & | stanza | ) |
| overridevirtual

You need to implement this method to process incoming XMPP stanzas.

You should return true if the stanza was handled and no further processing should occur, or false to let other extensions process the stanza.

End-to-end encrypted stanzas are not passed to this overload, for that purpose use the new overload instead.

Deprecated
  This is deprecated since QXmpp 1.5. Please use QXmppClientExtension::handleStanza(const QDomElement &stanza, const std::optional<QXmppE2eeMetadata> &e2eeMetadata). Currently both methods are called by the client, so only implement one!

Reimplemented from QXmppClientExtension.

## ◆ onRegistered()

void QXmppUploadRequestManager::onRegistered | ( | QXmppClient * | client | ) |
| overrideprotectedvirtual

Called after the extension has been added to a QXmppClient.

Parameters

  client |

Reimplemented from QXmppClientExtension.

## ◆ onUnregistered()

void QXmppUploadRequestManager::onUnregistered | ( | QXmppClient * | client | ) |
| overrideprotectedvirtual

Called after the extension has been removed from a QXmppClient.

Parameters

  client |

Reimplemented from QXmppClientExtension.

## ◆ requestFailed()

Q_SIGNAL void QXmppUploadRequestManager::requestFailed | ( | const QXmppHttpUploadRequestIq & | request | ) |

Emitted when the slot request failed.

Parameters

  request | The sent IQ with an QXmppStanza::Error from the server.

## ◆ requestSlot() [1/3]

auto QXmppUploadRequestManager::requestSlot | ( | const QFileInfo & | file,
|  | const QString & | customFileName,
|  | const QString & | uploadService = {} ) -> QXmppTask< SlotResult >

Requests an upload slot from the server.

Parameters

  file | The info of the file to be uploaded.
  customFileName | This name is used instead of the file's actual name for requesting the upload slot.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Since
  QXmpp 1.5

## ◆ requestSlot() [2/3]

auto QXmppUploadRequestManager::requestSlot | ( | const QFileInfo & | file,
|  | const QString & | uploadService = {} ) -> QXmppTask< SlotResult >

Requests an upload slot from the server.

Parameters

  file | The info of the file to be uploaded.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Since
  QXmpp 1.5

## ◆ requestSlot() [3/3]

auto QXmppUploadRequestManager::requestSlot | ( | const QString & | fileName,
|  | qint64 | fileSize,
|  | const QMimeType & | mimeType,
|  | const QString & | uploadService = {} ) -> QXmppTask< SlotResult >

Requests an upload slot from the server.

Parameters

  fileName | The name of the file to be uploaded. This may be used by the server to generate the URL.
  fileSize | The size of the file to be uploaded. The server may reject too large files.
  mimeType | The content-type of the file. This can be used by the server to set the HTTP MIME-type of the URL.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Since
  QXmpp 1.5

## ◆ requestUploadSlot() [1/3]

QString QXmppUploadRequestManager::requestUploadSlot | ( | const QFileInfo & | file,
|  | const QString & | customFileName,
|  | const QString & | uploadService = QString() )

Requests an upload slot from the server.

Parameters

  file | The info of the file to be uploaded.
  customFileName | This name is used instead of the file's actual name for requesting the upload slot.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Returns
  The id of the sent IQ. If sendPacket() isn't successful or no upload service has been discovered yet, an empty string will be returned.

## ◆ requestUploadSlot() [2/3]

QString QXmppUploadRequestManager::requestUploadSlot | ( | const QFileInfo & | file,
|  | const QString & | uploadService = QString() )

Requests an upload slot from the server.

Parameters

  file | The info of the file to be uploaded.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Returns
  The id of the sent IQ. If sendPacket() isn't successful or no upload service has been discovered yet, an empty string will be returned.

## ◆ requestUploadSlot() [3/3]

QString QXmppUploadRequestManager::requestUploadSlot | ( | const QString & | fileName,
|  | qint64 | fileSize,
|  | const QMimeType & | mimeType,
|  | const QString & | uploadService = QString() )

Requests an upload slot from the server.

Parameters

  fileName | The name of the file to be uploaded. This may be used by the server to generate the URL.
  fileSize | The size of the file to be uploaded. The server may reject too large files.
  mimeType | The content-type of the file. This can be used by the server to set the HTTP MIME-type of the URL.
  uploadService | The HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.

Returns
  The id of the sent IQ. If sendPacket() isn't successful or no upload service has been discovered yet, an empty string will be returned.

The documentation for this class was generated from the following files:

- QXmppUploadRequestManager.h
- QXmppUploadRequestManager.cpp