diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-02-01 16:50:34 +0100 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-02-03 00:11:35 +0100 |
| commit | 2dd54da9620028e1c051c3d4a9a6121ccab3f866 (patch) | |
| tree | ed68af9a65531f2a4ae46313cf8cd3beb0ad1cbb /src/base | |
| parent | b9c58b05300a292437c9554181970c7e1933b19e (diff) | |
| download | qxmpp-2dd54da9620028e1c051c3d4a9a6121ccab3f866.tar.gz | |
QXmppRegisterIq: Add utility methods to create common requests
This adds utility methods to create an unregistration or a change
password request in one line.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppRegisterIq.cpp | 36 | ||||
| -rw-r--r-- | src/base/QXmppRegisterIq.h | 5 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/base/QXmppRegisterIq.cpp b/src/base/QXmppRegisterIq.cpp index 79231c9a..de96aee9 100644 --- a/src/base/QXmppRegisterIq.cpp +++ b/src/base/QXmppRegisterIq.cpp @@ -65,6 +65,42 @@ QXmppRegisterIq::~QXmppRegisterIq() = default; QXmppRegisterIq &QXmppRegisterIq::operator=(const QXmppRegisterIq &other) = default; +/// Constructs a regular change password request. +/// +/// \param username The username of the account of which the password should be +/// changed. +/// \param newPassword The new password that should be set. +/// \param to Optional JID of the registration service. If this is omitted, the +/// IQ is automatically addressed to the local server. +/// +/// \since QXmpp 1.2 + +QXmppRegisterIq QXmppRegisterIq::createChangePasswordRequest(const QString &username, const QString &newPassword, const QString &to) +{ + QXmppRegisterIq iq; + iq.setType(QXmppIq::Set); + iq.setTo(to); + iq.setUsername(username); + iq.setPassword(newPassword); + return iq; +} + +/// Constructs a regular unregistration request. +/// +/// \param to Optional JID of the registration service. If this is omitted, the +/// IQ is automatically addressed to the local server. +/// +/// \since QXmpp 1.2 + +QXmppRegisterIq QXmppRegisterIq::createUnregistrationRequest(const QString &to) +{ + QXmppRegisterIq iq; + iq.setType(QXmppIq::Set); + iq.setTo(to); + iq.setRegisterType(QXmppRegisterIq::Remove); + return iq; +} + /// Returns the email for this registration IQ. QString QXmppRegisterIq::email() const diff --git a/src/base/QXmppRegisterIq.h b/src/base/QXmppRegisterIq.h index f952541d..83b53bc1 100644 --- a/src/base/QXmppRegisterIq.h +++ b/src/base/QXmppRegisterIq.h @@ -47,7 +47,7 @@ public: enum RegisterType { None, ///< No special register IQ. - Registered, ///< Used by the service to indicate that an account is already registered. + Registered, ///< Used by the service to indicate that an account is registered. Remove ///< Used by the client to request account removal. }; @@ -57,6 +57,9 @@ public: QXmppRegisterIq &operator=(const QXmppRegisterIq &other); + static QXmppRegisterIq createChangePasswordRequest(const QString &username, const QString &newPassword, const QString &to = {}); + static QXmppRegisterIq createUnregistrationRequest(const QString &to = {}); + QString email() const; void setEmail(const QString &email); |
