summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-10-08 21:59:42 (GMT)
committerTobias Markmann <tm@ayena.de>2012-10-08 22:04:15 (GMT)
commit8f75cf3d9892a3ce2c58537f29c851392231e29c (patch)
tree5239ce98c3e24780ba46d328f383c90cb84b35c7 /Swiften/Serializer/PayloadSerializers
parent53b7a6ad2d12fc5edc6a98726cabf1ea0b496505 (diff)
downloadswift-contrib-tobias/jingle.zip
swift-contrib-tobias/jingle.tar.bz2
Update XEP-0234 implementation to version 0.15 of the standard.tobias/jingle
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp12
-rw-r--r--Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.cpp63
-rw-r--r--Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h24
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp30
5 files changed, 110 insertions, 21 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index b4822cd..8946360 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -53,6 +53,7 @@
#include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferHashSerializer.h>
@@ -112,6 +113,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new WhiteboardSerializer());
serializers_.push_back(new StreamInitiationFileInfoSerializer());
+ serializers_.push_back(new JingleFileTransferFileInfoSerializer());
serializers_.push_back(new JingleContentPayloadSerializer());
serializers_.push_back(new JingleFileTransferDescriptionSerializer());
serializers_.push_back(new JingleFileTransferHashSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp
index 16337ff..1162a32 100644
--- a/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.cpp
@@ -14,7 +14,7 @@
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
-#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h>
namespace Swift {
@@ -23,19 +23,19 @@ JingleFileTransferDescriptionSerializer::JingleFileTransferDescriptionSerializer
std::string JingleFileTransferDescriptionSerializer::serializePayload(boost::shared_ptr<JingleFileTransferDescription> payload) const {
XMLElement description("description", "urn:xmpp:jingle:apps:file-transfer:3");
- StreamInitiationFileInfoSerializer fileInfoSerializer;
+ JingleFileTransferFileInfoSerializer fileInfoSerializer;
if (!payload->getOffers().empty()) {
boost::shared_ptr<XMLElement> offers = boost::make_shared<XMLElement>("offer");
- foreach(const StreamInitiationFileInfo &fileInfo, payload->getOffers()) {
- boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<StreamInitiationFileInfo>(fileInfo)));
+ foreach(const JingleFileTransferFileInfo &fileInfo, payload->getOffers()) {
+ boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<JingleFileTransferFileInfo>(fileInfo)));
offers->addNode(fileInfoXML);
}
description.addNode(offers);
}
if (!payload->getRequests().empty()) {
boost::shared_ptr<XMLElement> requests = boost::make_shared<XMLElement>("request");
- foreach(const StreamInitiationFileInfo &fileInfo, payload->getRequests()) {
- boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<StreamInitiationFileInfo>(fileInfo)));
+ foreach(const JingleFileTransferFileInfo &fileInfo, payload->getRequests()) {
+ boost::shared_ptr<XMLRawTextNode> fileInfoXML = boost::make_shared<XMLRawTextNode>(fileInfoSerializer.serialize(boost::make_shared<JingleFileTransferFileInfo>(fileInfo)));
requests->addNode(fileInfoXML);
}
description.addNode(requests);
diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.cpp
new file mode 100644
index 0000000..a13a40a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
+
+
+
+namespace Swift {
+
+JingleFileTransferFileInfoSerializer::JingleFileTransferFileInfoSerializer() {
+}
+
+std::string JingleFileTransferFileInfoSerializer::serializePayload(boost::shared_ptr<JingleFileTransferFileInfo> fileInfo) const {
+ XMLElement fileElement("file");
+
+ if (fileInfo->getDate() != stringToDateTime("")) {
+ boost::shared_ptr<XMLElement> date = boost::make_shared<XMLElement>("date", "", dateTimeToString(fileInfo->getDate()));
+ fileElement.addNode(date);
+ }
+ if (!fileInfo->getDescription().empty()) {
+ boost::shared_ptr<XMLElement> desc = boost::make_shared<XMLElement>("desc", "", fileInfo->getDescription());
+ fileElement.addNode(desc);
+ }
+ if (!fileInfo->getName().empty()) {
+ boost::shared_ptr<XMLElement> name = boost::make_shared<XMLElement>("name", "", fileInfo->getName());
+ fileElement.addNode(name);
+ }
+ if (fileInfo->getSupportsRangeRequests()) {
+ boost::shared_ptr<XMLElement> range = boost::make_shared<XMLElement>("range");
+ if (fileInfo->getRangeOffset() != 0) {
+ range->setAttribute("offset", boost::lexical_cast<std::string>(fileInfo->getRangeOffset()));
+ }
+ fileElement.addNode(range);
+ }
+ if (fileInfo->getSize() != 0) {
+ boost::shared_ptr<XMLElement> size = boost::make_shared<XMLElement>("size", "", boost::lexical_cast<std::string>(fileInfo->getSize()));
+ fileElement.addNode(size);
+ }
+ if (!fileInfo->getHash().empty()) {
+ boost::shared_ptr<XMLElement> hash = boost::make_shared<XMLElement>("hash", "urn:xmpp:hashes:1", fileInfo->getHash());
+ if (!fileInfo->getAlgo().empty()) {
+ hash->setAttribute("algo", fileInfo->getAlgo());
+ }
+ fileElement.addNode(hash);
+ }
+
+ return fileElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h
new file mode 100644
index 0000000..6f468d7
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/JingleFileTransferFileInfoSerializer.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/JingleFileTransferFileInfo.h>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+ class PayloadSerializerCollection;
+
+ class SWIFTEN_API JingleFileTransferFileInfoSerializer : public GenericPayloadSerializer<JingleFileTransferFileInfo> {
+ public:
+ JingleFileTransferFileInfoSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<JingleFileTransferFileInfo>) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
index e3ec8fc..10aa7e9 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
@@ -181,14 +181,13 @@ class JingleSerializersTest : public CppUnit::TestFixture {
void testSerialize_Xep0234_Example1() {
std::string expected = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">"
"<offer>"
- "<file"
- " date=\"1969-07-21T02:56:15Z\""
- " hash=\"552da749930852c69ae5d2141d3766b1\""
- " name=\"test.txt\""
- " size=\"1022\""
- " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">"
+ "<file>"
+ "<date>1969-07-21T02:56:15Z</date>"
"<desc>This is a test. If this were a real file...</desc>"
+ "<name>test.txt</name>"
"<range/>"
+ "<size>1022</size>"
+ "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">552da749930852c69ae5d2141d3766b1</hash>"
"</file>"
"</offer>"
"</description>";
@@ -197,6 +196,7 @@ class JingleSerializersTest : public CppUnit::TestFixture {
fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z"));
fileInfo.setHash("552da749930852c69ae5d2141d3766b1");
+ fileInfo.setAlgo("sha-1");
fileInfo.setSize(1022);
fileInfo.setName("test.txt");
fileInfo.setDescription("This is a test. If this were a real file...");
@@ -217,14 +217,13 @@ class JingleSerializersTest : public CppUnit::TestFixture {
"<content creator=\"initiator\" name=\"a-file-offer\">"
"<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">"
"<offer>"
- "<file"
- " date=\"1969-07-21T02:56:15Z\""
- " hash=\"552da749930852c69ae5d2141d3766b1\""
- " name=\"test.txt\""
- " size=\"1022\""
- " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">"
+ "<file>"
+ "<date>1969-07-21T02:56:15Z</date>"
"<desc>This is a test. If this were a real file...</desc>"
+ "<name>test.txt</name>"
"<range/>"
+ "<size>1022</size>"
+ "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">552da749930852c69ae5d2141d3766b1</hash>"
"</file>"
"</offer>"
"</description>"
@@ -266,6 +265,7 @@ class JingleSerializersTest : public CppUnit::TestFixture {
StreamInitiationFileInfo fileInfo;
fileInfo.setName("test.txt");
fileInfo.setSize(1022);
+ fileInfo.setAlgo("sha-1");
fileInfo.setHash("552da749930852c69ae5d2141d3766b1");
fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z"));
fileInfo.setDescription("This is a test. If this were a real file...");
@@ -350,10 +350,9 @@ class JingleSerializersTest : public CppUnit::TestFixture {
"<description"
" xmlns=\"urn:xmpp:jingle:apps:file-transfer:3\">"
"<request>"
- "<file"
- " hash=\"552da749930852c69ae5d2141d3766b1\""
- " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">"
+ "<file>"
"<range offset=\"270336\"/>"
+ "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">552da749930852c69ae5d2141d3766b1</hash>"
"</file>"
"</request>"
"</description>"
@@ -393,6 +392,7 @@ class JingleSerializersTest : public CppUnit::TestFixture {
StreamInitiationFileInfo fileInfo;
fileInfo.setHash("552da749930852c69ae5d2141d3766b1");
+ fileInfo.setAlgo("sha-1");
fileInfo.setRangeOffset(270336);
JingleFileTransferDescription::ref desc = boost::make_shared<JingleFileTransferDescription>();