diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-03 12:01:45 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-03 12:01:45 +0200 |
| commit | 6f087827d2c08a1e7edc70d389521fcaf138c6e8 (patch) | |
| tree | 03b7fe2f7e6114ce658e33aa438f12749079c0fc | |
| parent | a8443321caeedab90f82be99cf9fe388666c32cb (diff) | |
| download | qxmpp-6f087827d2c08a1e7edc70d389521fcaf138c6e8.tar.gz | |
add QXmppExtendedAddress
| -rw-r--r-- | src/base/QXmppStanza.cpp | 128 | ||||
| -rw-r--r-- | src/base/QXmppStanza.h | 45 | ||||
| -rw-r--r-- | tests/stanza.cpp | 67 | ||||
| -rw-r--r-- | tests/stanza.h | 34 | ||||
| -rw-r--r-- | tests/tests.cpp | 4 | ||||
| -rw-r--r-- | tests/tests.pro | 2 |
6 files changed, 278 insertions, 2 deletions
diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index 56cdba0a..08cd97f2 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -1,8 +1,10 @@ /* * Copyright (C) 2008-2012 The QXmpp developers * - * Author: + * Authors: * Manjeet Dahiya + * Jeremy Lainé + * Georg Rudoy * * Source: * http://code.google.com/p/qxmpp @@ -31,6 +33,130 @@ uint QXmppStanza::s_uniqeIdNo = 0; +class QXmppExtendedAddressPrivate : public QSharedData +{ +public: + bool delivered; + QString description; + QString jid; + QString type; +}; + +/// Constructs an empty extended address. + +QXmppExtendedAddress::QXmppExtendedAddress() + : d(new QXmppExtendedAddressPrivate()) +{ + d->delivered = false; +} + +/// Constructs a copy of other. +/// +/// \param other +/// +QXmppExtendedAddress::QXmppExtendedAddress(const QXmppExtendedAddress &other) + : d(other.d) +{ +} + +QXmppExtendedAddress::~QXmppExtendedAddress() +{ +} + +/// Assigns the other address to this one. +/// +/// \param other +/// +QXmppExtendedAddress& QXmppExtendedAddress::operator=(const QXmppExtendedAddress& other) +{ + d = other.d; + return *this; +} + +/// Returns the human-readable description of the address. + +QString QXmppExtendedAddress::description() const +{ + return d->description; +} + +/// Sets the human-readable \a description of the address. + +void QXmppExtendedAddress::setDescription(const QString &description) +{ + d->description = description; +} + +/// Returns the JID of the address. + +QString QXmppExtendedAddress::jid() const +{ + return d->jid; +} + +/// Sets the JID of the address. + +void QXmppExtendedAddress::setJid(const QString &jid) +{ + d->jid = jid; +} + +/// Returns the type of the address. + +QString QXmppExtendedAddress::type() const +{ + return d->type; +} + +/// Sets the \a type of the address. + +void QXmppExtendedAddress::setType(const QString &type) +{ + d->type = type; +} + +/// Returns whether the stanza has been delivered to this address. + +bool QXmppExtendedAddress::isDelivered() const +{ + return d->delivered; +} + +/// Sets whether the stanza has been \a delivered to this address. + +void QXmppExtendedAddress::setDelivered(bool delivered) +{ + d->delivered = delivered; +} + +/// Checks whether this address is valid. The extended address is considered +/// to be valid if at least type and JID fields are non-empty. + +bool QXmppExtendedAddress::isValid() const +{ + return !d->type.isEmpty() && !d->jid.isEmpty(); +} + +void QXmppExtendedAddress::parse(const QDomElement &element) +{ + d->delivered = element.attribute("delivered") == "true"; + d->description = element.attribute("desc"); + d->jid = element.attribute("jid"); + d->type = element.attribute("type"); +} + +void QXmppExtendedAddress::toXml(QXmlStreamWriter *xmlWriter) +{ + xmlWriter->writeStartElement("address"); + if (d->delivered) + xmlWriter->writeAttribute("delivered", "true"); + if (!d->description.isEmpty()) + xmlWriter->writeAttribute("desc", d->description); + xmlWriter->writeAttribute("jid", d->jid); + xmlWriter->writeAttribute("type", d->type); + xmlWriter->writeEndElement(); +} + QXmppStanza::Error::Error(): m_code(0), m_type(static_cast<QXmppStanza::Error::Type>(-1)), diff --git a/src/base/QXmppStanza.h b/src/base/QXmppStanza.h index 10825b36..48439c34 100644 --- a/src/base/QXmppStanza.h +++ b/src/base/QXmppStanza.h @@ -1,8 +1,10 @@ /* * Copyright (C) 2008-2012 The QXmpp developers * - * Author: + * Authors: * Manjeet Dahiya + * Jeremy Lainé + * Georg Rudoy * * Source: * http://code.google.com/p/qxmpp @@ -37,6 +39,47 @@ #include "QXmppElement.h" +class QXmppExtendedAddressPrivate; + +/// \brief Represents an extended address as in XEP-0033. +/// +/// Extended addresses maybe of different types. While XEP-0033 explicitly defines +/// some of them, other XEPs introduce other types (like the Remote Controlling +/// Clients XEP, for example). That's why extended address' type is a string rather +/// then a member of some enum. + +class QXMPP_EXPORT QXmppExtendedAddress +{ +public: + QXmppExtendedAddress(); + QXmppExtendedAddress(const QXmppExtendedAddress&); + ~QXmppExtendedAddress(); + + QXmppExtendedAddress& operator=(const QXmppExtendedAddress&); + + QString description() const; + void setDescription(const QString &description); + + QString jid() const; + void setJid(const QString &jid); + + QString type() const; + void setType(const QString &type); + + bool isDelivered() const; + void setDelivered(bool); + + bool isValid() const; + + /// \cond + void parse(const QDomElement &element); + void toXml(QXmlStreamWriter *writer); + /// \endcond + +private: + QSharedDataPointer<QXmppExtendedAddressPrivate> d; +}; + class QXmppStanzaPrivate; /// \defgroup Stanzas diff --git a/tests/stanza.cpp b/tests/stanza.cpp new file mode 100644 index 00000000..ddc18078 --- /dev/null +++ b/tests/stanza.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppStanza.h" + +#include "stanza.h" +#include "tests.h" + +void tst_QXmppStanza::testExtendedAddress_data() +{ + QTest::addColumn<QByteArray>("xml"); + QTest::addColumn<bool>("delivered"); + QTest::addColumn<QString>("description"); + QTest::addColumn<QString>("jid"); + QTest::addColumn<QString>("type"); + + QTest::newRow("simple") + << QByteArray("<address jid=\"foo@example.com/QXmpp\" type=\"bcc\"/>") + << false + << QString() + << QString("foo@example.com/QXmpp") + << QString("bcc"); + + QTest::newRow("full") + << QByteArray("<address delivered=\"true\" desc=\"some description\" jid=\"foo@example.com/QXmpp\" type=\"bcc\"/>") + << true + << QString("some description") + << QString("foo@example.com/QXmpp") + << QString("bcc"); +} + +void tst_QXmppStanza::testExtendedAddress() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, delivered); + QFETCH(QString, description); + QFETCH(QString, jid); + QFETCH(QString, type); + + QXmppExtendedAddress address; + parsePacket(address, xml); + QCOMPARE(address.isDelivered(), delivered); + QCOMPARE(address.description(), description); + QCOMPARE(address.jid(), jid); + QCOMPARE(address.type(), type); + serializePacket(address, xml); +} diff --git a/tests/stanza.h b/tests/stanza.h new file mode 100644 index 00000000..8bd57d90 --- /dev/null +++ b/tests/stanza.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include <QObject> + +class tst_QXmppStanza : public QObject +{ + Q_OBJECT + +private slots: + void testExtendedAddress_data(); + void testExtendedAddress(); +}; + diff --git a/tests/tests.cpp b/tests/tests.cpp index 2adaed57..cd1d4a14 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -56,6 +56,7 @@ #include "rsm.h" #include "rtp.h" #include "sasl.h" +#include "stanza.h" #include "stun.h" #include "tests.h" #include "vcard.h" @@ -937,6 +938,9 @@ int main(int argc, char *argv[]) TestServer testServer; errors += QTest::qExec(&testServer); + tst_QXmppStanza testStanza; + errors += QTest::qExec(&testStanza); + TestStun testStun; errors += QTest::qExec(&testStun); diff --git a/tests/tests.pro b/tests/tests.pro index 068a672e..0d44fa68 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -17,6 +17,7 @@ SOURCES += \ rpc.cpp \ rsm.cpp \ rtp.cpp \ + stanza.cpp \ stun.cpp \ tests.cpp \ vcard.cpp @@ -31,6 +32,7 @@ HEADERS += \ rpc.h \ rsm.h \ rtp.h \ + stanza.h \ stun.h \ tests.h \ vcard.h |
