From 7e66378dc28da241e633ffb4ee4ece7afe1ee1ce Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Mon, 11 Oct 2010 11:50:16 +0000 Subject: encode / decode presence photo hash to / from base64 --- src/QXmppPresence.cpp | 6 +++--- tests/tests.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/QXmppPresence.cpp b/src/QXmppPresence.cpp index f6e58b6f..00746fdd 100644 --- a/src/QXmppPresence.cpp +++ b/src/QXmppPresence.cpp @@ -84,7 +84,7 @@ void QXmppPresence::parse(const QDomElement &element) QDomElement photoElement = xElement.firstChildElement("photo"); if(!photoElement.isNull()) { - m_photoHash = photoElement.text().toUtf8(); + m_photoHash = QByteArray::fromBase64(photoElement.text().toAscii()); if(m_photoHash.isEmpty()) m_vCardUpdateType = PhotoNotAdvertized; else @@ -92,7 +92,7 @@ void QXmppPresence::parse(const QDomElement &element) } else { - m_photoHash = ""; + m_photoHash = QByteArray(); m_vCardUpdateType = PhotoNotReady; } } @@ -149,7 +149,7 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const helperToXmlAddTextElement(xmlWriter, "photo", ""); break; case PhotoAdvertised: - helperToXmlAddTextElement(xmlWriter, "photo", m_photoHash); + helperToXmlAddTextElement(xmlWriter, "photo", m_photoHash.toBase64()); break; case PhotoNotReady: break; diff --git a/tests/tests.cpp b/tests/tests.cpp index 67217a81..3270a81f 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -437,7 +437,7 @@ void TestPackets::testPresenceWithVCardUpdate() "In a meeting" "5" "" - "sha1-hash-of-image" + "Ve0tKBkyTOPyZrekN6VJl6ZZZfQ=" "" ""); @@ -448,7 +448,7 @@ void TestPackets::testPresenceWithVCardUpdate() QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); - QCOMPARE(presence.photoHash(), QByteArray("sha1-hash-of-image")); + QCOMPARE(presence.photoHash(), QByteArray::fromBase64("Ve0tKBkyTOPyZrekN6VJl6ZZZfQ=")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::PhotoAdvertised); serializePacket(presence, xml); } @@ -461,7 +461,7 @@ void TestPackets::testPresenceWithCapability() "In a meeting" "5" "" - "sha1-hash-of-image" + "Ve0tKBkyTOPyZrekN6VJl6ZZZfQ=" "" "" ""); @@ -473,7 +473,7 @@ void TestPackets::testPresenceWithCapability() QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); - QCOMPARE(presence.photoHash(), QByteArray("sha1-hash-of-image")); + QCOMPARE(presence.photoHash(), QByteArray::fromBase64("Ve0tKBkyTOPyZrekN6VJl6ZZZfQ=")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::PhotoAdvertised); QCOMPARE(presence.capabilityHash(), QString("sha-1")); QCOMPARE(presence.capabilityNode(), QString("http://code.google.com/p/qxmpp")); -- cgit v1.2.3