diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-03-31 21:45:44 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-04-01 14:06:06 +0200 |
| commit | 49ead66e9b4d5914dfd9c33e62b0311d4d8eb940 (patch) | |
| tree | 33b7a03b4cc8cd9efd288eff8885c9b03a8f022a /src/base/QXmppStanza.cpp | |
| parent | 03764c9abcd3c79873038935566f4e31a845ada9 (diff) | |
| download | qxmpp-49ead66e9b4d5914dfd9c33e62b0311d4d8eb940.tar.gz | |
QXmppStanza::Error: Add redirection URI from RFC6120
The error conditions <gone/> and <redirect/> can contain an XMPP URI to
redirect to as defined in RFC6120.
Diffstat (limited to 'src/base/QXmppStanza.cpp')
| -rw-r--r-- | src/base/QXmppStanza.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index 1a870935..c4fae8de 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -165,6 +165,7 @@ public: QXmppStanza::Error::Type type; QXmppStanza::Error::Condition condition; QString text; + QString redirectionUri; // XEP-0363: HTTP File Upload bool fileTooLarge; @@ -255,6 +256,9 @@ void QXmppStanza::Error::setCode(int code) /// /// Returns the error condition. /// +/// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect +/// can be used in combination with redirectUri(). +/// QXmppStanza::Error::Condition QXmppStanza::Error::condition() const { return d->condition; @@ -263,6 +267,9 @@ QXmppStanza::Error::Condition QXmppStanza::Error::condition() const /// /// Sets the error condition. /// +/// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect +/// can be used in combination with setRedirectUri(). +/// void QXmppStanza::Error::setCondition(QXmppStanza::Error::Condition cond) { d->condition = cond; @@ -284,6 +291,32 @@ void QXmppStanza::Error::setType(QXmppStanza::Error::Type type) d->type = type; } +/// +/// Returns the optionally included redirection URI for the error conditions +/// QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect. +/// +/// \sa setRedirectionUri() +/// +/// \since QXmpp 1.3 +/// +QString QXmppStanza::Error::redirectionUri() const +{ + return d->redirectionUri; +} + +/// +/// Sets the optional redirection URI for the error conditions +/// QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect. +/// +/// \sa redirectionUri() +/// +/// \since QXmpp 1.3 +/// +void QXmppStanza::Error::setRedirectionUri(const QString &redirectionUri) +{ + d->redirectionUri = redirectionUri; +} + /// Returns true, if an HTTP File Upload failed, because the file was too /// large. /// @@ -395,12 +428,22 @@ void QXmppStanza::Error::parse(const QDomElement &errorElement) QDomElement element = errorElement.firstChildElement(); while (!element.isNull()) { if (element.namespaceURI() == ns_stanza) { - if (element.tagName() == QStringLiteral("text")) + if (element.tagName() == QStringLiteral("text")) { setText(element.text()); - else + } else { setConditionFromStr(element.tagName()); - // XEP-0363: HTTP File Upload + + // redirection URI + if (d->condition == Gone || d->condition == Redirect) { + d->redirectionUri = element.text(); + + // .text() returns empty string if nothing was set + if (d->redirectionUri.isEmpty()) + d->redirectionUri.clear(); + } + } } else if (element.namespaceURI() == ns_http_upload) { + // XEP-0363: HTTP File Upload // file is too large if (element.tagName() == QStringLiteral("file-too-large")) { d->fileTooLarge = true; @@ -434,6 +477,12 @@ void QXmppStanza::Error::toXml(QXmlStreamWriter *writer) const if (!cond.isEmpty()) { writer->writeStartElement(cond); writer->writeDefaultNamespace(ns_stanza); + + // redirection URI + if (!d->redirectionUri.isEmpty() && (d->condition == Gone || d->condition == Redirect)) { + writer->writeCharacters(d->redirectionUri); + } + writer->writeEndElement(); } if (!d->text.isEmpty()) { |
