diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-15 15:37:56 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-15 15:37:56 +0000 |
| commit | 7077786fa916076f2427cef89588e6b835976f0e (patch) | |
| tree | 0198c62ce53ea7c482a42241f6ef5d7cc608578b /source/QXmppDiscoveryIq.cpp | |
| parent | 93931fb5172de50ddc074ba119218a39ef46ae49 (diff) | |
| download | qxmpp-7077786fa916076f2427cef89588e6b835976f0e.tar.gz | |
add support for generating XEP-0115 verification strings
Diffstat (limited to 'source/QXmppDiscoveryIq.cpp')
| -rw-r--r-- | source/QXmppDiscoveryIq.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/source/QXmppDiscoveryIq.cpp b/source/QXmppDiscoveryIq.cpp index a308161a..866c82f7 100644 --- a/source/QXmppDiscoveryIq.cpp +++ b/source/QXmppDiscoveryIq.cpp @@ -21,11 +21,37 @@ * */ +#include <QCryptographicHash> +#include <QDomElement> + #include "QXmppConstants.h" #include "QXmppDiscoveryIq.h" #include "QXmppUtils.h" -#include <QDomElement> +static bool identityLessThan(const QXmppDiscoveryIq::Identity &i1, const QXmppDiscoveryIq::Identity &i2) +{ + if (i1.category() < i2.category()) + return true; + else if (i1.category() > i2.category()) + return false; + + if (i1.type() < i2.type()) + return true; + else if (i1.type() > i2.type()) + return false; + + if (i1.language() < i2.language()) + return true; + else if (i1.language() > i2.language()) + return false; + + if (i1.name() < i2.name()) + return true; + else if (i1.name() > i2.name()) + return false; + + return false; +} QString QXmppDiscoveryIq::Identity::category() const { @@ -37,6 +63,16 @@ void QXmppDiscoveryIq::Identity::setCategory(const QString &category) m_category = category; } +QString QXmppDiscoveryIq::Identity::language() const +{ + return m_language; +} + +void QXmppDiscoveryIq::Identity::setLanguage(const QString &language) +{ + m_language = language; +} + QString QXmppDiscoveryIq::Identity::name() const { return m_name; @@ -137,6 +173,24 @@ void QXmppDiscoveryIq::setQueryType(enum QXmppDiscoveryIq::QueryType type) m_queryType = type; } +/// Calculate the verification string for XEP-0115 : Entity Capabilities + +QByteArray QXmppDiscoveryIq::verificationString() const +{ + QString S; + QList<QXmppDiscoveryIq::Identity> sortedIdentities = m_identities; + qSort(sortedIdentities.begin(), sortedIdentities.end(), identityLessThan); + QStringList sortedFeatures = m_features; + qSort(sortedFeatures); + foreach (const QXmppDiscoveryIq::Identity &identity, sortedIdentities) + S += QString("%1/%2/%3/%4<").arg(identity.category(), identity.type(), identity.language(), identity.name()); + foreach (const QString &feature, sortedFeatures) + S += feature + QLatin1String("<"); + QCryptographicHash hasher(QCryptographicHash::Sha1); + hasher.addData(S.toUtf8()); + return hasher.result(); +} + bool QXmppDiscoveryIq::isDiscoveryIq(const QDomElement &element) { QDomElement queryElement = element.firstChildElement("query"); @@ -161,6 +215,7 @@ void QXmppDiscoveryIq::parseElementFromChild(const QDomElement &element) m_features.append(itemElement.attribute("var")); } else if (itemElement.tagName() == "identity") { QXmppDiscoveryIq::Identity identity; + identity.setLanguage(itemElement.attribute("xml:lang")); identity.setCategory(itemElement.attribute("category")); identity.setName(itemElement.attribute("name")); identity.setType(itemElement.attribute("type")); @@ -193,6 +248,7 @@ void QXmppDiscoveryIq::toXmlElementFromChild(QXmlStreamWriter *writer) const foreach (const QXmppDiscoveryIq::Identity& identity, m_identities) { writer->writeStartElement("identity"); + helperToXmlAddAttribute(writer, "xml:lang", identity.language()); helperToXmlAddAttribute(writer, "category", identity.category()); helperToXmlAddAttribute(writer, "name", identity.name()); helperToXmlAddAttribute(writer, "type", identity.type()); |
