QXmpp Version: 1.10.0
Public Types | Signals | Public Member Functions | Protected Member Functions | List of all members
QXmppUploadRequestManager Class Reference

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

#include <QXmppUploadRequestManager.h>

Inheritance diagram for QXmppUploadRequestManager:
Inheritance graph
[legend]
Collaboration diagram for QXmppUploadRequestManager:
Collaboration graph
[legend]

Public Types

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

Signals

void slotReceived (const QXmppHttpUploadSlotIq &slot)
 Emitted when an upload slot was received.
 
void requestFailed (const QXmppHttpUploadRequestIq &request)
 
void serviceFoundChanged ()
 Emitted when the first upload service has been found.
 
- Signals inherited from QXmppLoggable
void setGauge (const QString &gauge, double value)
 Sets the given gauge to value.
 
void logMessage (QXmppLogger::MessageType type, const QString &msg)
 This signal is emitted to send logging messages.
 
void updateCounter (const QString &counter, qint64 amount=1)
 Updates the given counter by amount.
 

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())
 
QXmppTask< SlotResultrequestSlot (const QFileInfo &file, const QString &uploadService={})
 
QXmppTask< SlotResultrequestSlot (const QFileInfo &file, const QString &customFileName, const QString &uploadService={})
 
QXmppTask< SlotResultrequestSlot (const QString &fileName, qint64 fileSize, const QMimeType &mimeType, const QString &uploadService={})
 
bool serviceFound () const
 Returns true if an HTTP File Upload service has been discovered.
 
QVector< QXmppUploadServiceuploadServices () 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. More...
 
- Public Member Functions inherited from QXmppClientExtension
 QXmppClientExtension ()
 
virtual QStringList discoveryFeatures () const
 
virtual QList< QXmppDiscoveryIq::IdentitydiscoveryIdentities () const
 
virtual bool handleStanza (const QDomElement &stanza)
 You need to implement this method to process incoming XMPP stanzas. More...
 
virtual bool handleStanza (const QDomElement &stanza, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
 You need to implement this method to process incoming XMPP stanzas. More...
 
- Public Member Functions inherited from QXmppLoggable
 QXmppLoggable (QObject *parent=nullptr)
 

Protected Member Functions

void onRegistered (QXmppClient *client) override
 
void onUnregistered (QXmppClient *client) override
 
- Protected Member Functions inherited from QXmppClientExtension
QXmppClientclient () const
 
virtual void setClient (QXmppClient *client)
 
virtual void onRegistered (QXmppClient *client)
 
virtual void onUnregistered (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)
 
void info (const QString &message)
 
void warning (const QString &message)
 
void logReceived (const QString &message)
 
void logSent (const QString &message)
 

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);
QXmppClient * client() const
Definition: QXmppClientExtension.cpp:57
bool addExtension(QXmppClientExtension *extension)
Registers a new extension with the client.
Definition: QXmppClient.cpp:376
The QXmppUploadRequestManager implements the core of XEP-0369: HTTP File Upload.
Definition: QXmppUploadRequestManager.h:85

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

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

void QXmppUploadRequestManager::requestFailed ( const QXmppHttpUploadRequestIq request)
signal

Emitted when the slot request failed.

Parameters
requestThe sent IQ with an QXmppStanza::Error from the server.

◆ requestSlot() [1/3]

auto QXmppUploadRequestManager::requestSlot ( const QFileInfo &  file,
const QString &  customFileName,
const QString &  uploadService = {} 
)

Requests an upload slot from the server.

Parameters
fileThe info of the file to be uploaded.
customFileNameThis name is used instead of the file's actual name for requesting the upload slot.
uploadServiceThe HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.
Warning
THIS API IS NOT FINALIZED YET!
Since
QXmpp 1.5

◆ requestSlot() [2/3]

auto QXmppUploadRequestManager::requestSlot ( const QFileInfo &  file,
const QString &  uploadService = {} 
)

Requests an upload slot from the server.

Parameters
fileThe info of the file to be uploaded.
uploadServiceThe HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.
Warning
THIS API IS NOT FINALIZED YET!
Since
QXmpp 1.5

◆ requestSlot() [3/3]

auto QXmppUploadRequestManager::requestSlot ( const QString &  fileName,
qint64  fileSize,
const QMimeType &  mimeType,
const QString &  uploadService = {} 
)

Requests an upload slot from the server.

Parameters
fileNameThe name of the file to be uploaded. This may be used by the server to generate the URL.
fileSizeThe size of the file to be uploaded. The server may reject too large files.
mimeTypeThe content-type of the file. This can be used by the server to set the HTTP MIME-type of the URL.
uploadServiceThe HTTP File Upload service that is used to request the upload slot. If this is empty, the first discovered one is used.
Warning
THIS API IS NOT FINALIZED YET!
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
fileThe info of the file to be uploaded.
customFileNameThis name is used instead of the file's actual name for requesting the upload slot.
uploadServiceThe 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
fileThe info of the file to be uploaded.
uploadServiceThe 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
fileNameThe name of the file to be uploaded. This may be used by the server to generate the URL.
fileSizeThe size of the file to be uploaded. The server may reject too large files.
mimeTypeThe content-type of the file. This can be used by the server to set the HTTP MIME-type of the URL.
uploadServiceThe 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: