QXmpp  Version:1.3.0
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]

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())
 
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 ()
 
 ~QXmppClientExtension () override
 
virtual QStringList discoveryFeatures () const
 
virtual QList< QXmppDiscoveryIq::IdentitydiscoveryIdentities () const
 
- Public Member Functions inherited from QXmppLoggable
 QXmppLoggable (QObject *parent=nullptr)
 

Protected Member Functions

void setClient (QXmppClient *client) override
 
- Protected Member Functions inherited from QXmppClientExtension
QXmppClientclient ()
 
- 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);

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 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.

Implements 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.

◆ 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.

◆ setClient()

void QXmppUploadRequestManager::setClient ( QXmppClient client)
overrideprotectedvirtual

Sets the client which loaded this extension.

Parameters
client

Reimplemented from QXmppClientExtension.


The documentation for this class was generated from the following files:
QXmppClientExtension::client
QXmppClient * client()
Definition: QXmppClientExtension.cpp:70
QXmppClient::addExtension
bool addExtension(QXmppClientExtension *extension)
Definition: QXmppClient.cpp:181
QXmppUploadRequestManager
The QXmppUploadRequestManager implements the core of XEP-0369: HTTP File Upload.
Definition: QXmppUploadRequestManager.h:97