summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h15
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h8
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp79
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h29
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp43
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h10
-rw-r--r--Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp8
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp257
10 files changed, 271 insertions, 239 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index fe61c72..812e968 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -78,6 +78,7 @@
#include <Swiften/Parser/PayloadParsers/StatusShowParser.h>
#include <Swiften/Parser/PayloadParsers/StorageParser.h>
#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h>
+#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h>
#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h>
#include <Swiften/Parser/PayloadParsers/SubjectParser.h>
#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>
@@ -140,6 +141,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1"));
factories_.push_back(boost::make_shared<JingleFileTransferDescriptionParserFactory>(this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferReceivedParser> >("received", "urn:xmpp:jingle:apps:file-transfer:3"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams"));
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp
index b394115..fb1836f 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp
@@ -4,72 +4,59 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
-#include "JingleFileTransferDescriptionParser.h"
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h>
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Base/Log.h>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/StringCodecs/Base64.h>
namespace Swift {
-JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0),
- currentElement(UnknownElement) {
-
+JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) {
}
void JingleFileTransferDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
- if (level == 0) {
-
- }
-
if (level == 1) {
- if (element == "offer") {
- currentElement = OfferElement;
- } else if (element == "request") {
- currentElement = RequestElement;
- } else {
- currentElement = UnknownElement;
- }
- }
-
- if (level == 2) {
PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes);
if (payloadParserFactory) {
currentPayloadParser.reset(payloadParserFactory->createPayloadParser());
}
}
- if (level >= 2 && currentPayloadParser) {
+ if (level >= 1 && currentPayloadParser) {
currentPayloadParser->handleStartElement(element, ns, attributes);
}
-
++level;
}
void JingleFileTransferDescriptionParser::handleEndElement(const std::string& element, const std::string& ns) {
--level;
- if (currentPayloadParser) {
- if (level >= 2) {
- currentPayloadParser->handleEndElement(element, ns);
- }
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
- if (level == 2) {
- boost::shared_ptr<StreamInitiationFileInfo> info = boost::dynamic_pointer_cast<StreamInitiationFileInfo>(currentPayloadParser->getPayload());
- if (info) {
- if (currentElement == OfferElement) {
- getPayloadInternal()->addOffer(*info);
- } else if (currentElement == RequestElement) {
- getPayloadInternal()->addRequest(*info);
- }
- }
+ if (level == 0) {
+ boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload());
+ if (info) {
+ getPayloadInternal()->setFileInfo(*info);
}
}
}
void JingleFileTransferDescriptionParser::handleCharacterData(const std::string& data) {
- if (level >= 2 && currentPayloadParser) {
+ if (level >= 1 && currentPayloadParser) {
currentPayloadParser->handleCharacterData(data);
}
}
-
+
}
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
index 7ea22b4..a1215c1 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <Swiften/Elements/JingleFileTransferDescription.h>
@@ -20,18 +26,11 @@ class JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFi
virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
virtual void handleEndElement(const std::string& element, const std::string&);
- virtual void handleCharacterData(const std::string& data);
+ virtual void handleCharacterData(const std::string& data);
private:
- enum CurrentParseElement {
- UnknownElement,
- RequestElement,
- OfferElement
- };
-
PayloadParserFactoryCollection* factories;
int level;
- CurrentParseElement currentElement;
boost::shared_ptr<PayloadParser> currentPayloadParser;
};
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h
index b997c1d..7bd4b8a 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <Swiften/Parser/GenericPayloadParserFactory.h>
@@ -19,7 +25,7 @@ namespace Swift {
}
virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const {
- return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:3";
+ return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:4";
}
virtual PayloadParser* createPayloadParser() {
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp
new file mode 100644
index 0000000..2a62f23
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h>
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/StringCodecs/Base64.h>
+
+namespace Swift {
+
+JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) {
+}
+
+template<typename T> boost::optional<T> safeLexicalCast(const std::string& str) {
+ boost::optional<T> ret;
+ try {
+ ret = boost::lexical_cast<T>(str);
+ } catch (boost::bad_lexical_cast &) {
+
+ }
+ return ret;
+}
+
+void JingleFileTransferFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ charData.clear();
+ if (element == "hash") {
+ hashAlg = attributes.getAttributeValue("algo").get_value_or("");
+ }
+ else if (element == "range") {
+ rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or(""));
+ }
+
+ ++level;
+}
+
+void JingleFileTransferFileInfoParser::handleEndElement(const std::string& element, const std::string&) {
+ --level;
+ if (level == 1) {
+ if (element == "date") {
+ getPayloadInternal()->setDate(stringToDateTime(charData));
+ }
+ else if (element == "desc") {
+ getPayloadInternal()->setDescription(charData);
+ }
+ else if (element == "media-type") {
+ getPayloadInternal()->setMediaType(charData);
+ }
+ else if (element == "name") {
+ getPayloadInternal()->setName(charData);
+ }
+ else if (element == "size") {
+ boost::optional<boost::uintmax_t> size = safeLexicalCast<boost::uintmax_t>(charData);
+ if (size) {
+ getPayloadInternal()->setSize(size.get());
+ }
+ }
+ else if (element == "range") {
+ getPayloadInternal()->setSupportsRangeRequests(true);
+ if (rangeOffset) {
+ getPayloadInternal()->setRangeOffset(rangeOffset.get_value_or(0));
+ }
+ }
+ else if (element == "hash") {
+ getPayloadInternal()->addHash(HashElement(hashAlg, Base64::decode(charData)));
+ }
+ }
+}
+
+void JingleFileTransferFileInfoParser::handleCharacterData(const std::string& data) {
+ charData += data;
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h
new file mode 100644
index 0000000..eb6245c
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/JingleFileTransferFileInfo.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+
+class JingleFileTransferFileInfoParser : public GenericPayloadParser<JingleFileTransferFileInfo> {
+ public:
+ JingleFileTransferFileInfoParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string&);
+ virtual void handleCharacterData(const std::string& data);
+
+ private:
+ int level;
+ std::string charData;
+ std::string hashAlg;
+ boost::optional<boost::uintmax_t> rangeOffset;
+};
+
+}
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp
index 87f8317..6a1a031 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp
@@ -4,39 +4,54 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
#include "JingleFileTransferHashParser.h"
#include <boost/shared_ptr.hpp>
#include <boost/algorithm/string.hpp>
-#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h>
+#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h>
#include <Swiften/Parser/GenericPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParserFactory.h>
namespace Swift {
-JingleFileTransferHashParser::JingleFileTransferHashParser() {
+JingleFileTransferHashParser::JingleFileTransferHashParser() : level(0) {
}
-void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
- if (element == "hash") {
- algo = attributes.getAttribute("algo");
+void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 1 && element == "file") {
+ currentPayloadParser = boost::make_shared<JingleFileTransferFileInfoParser>();
}
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
}
-void JingleFileTransferHashParser::handleEndElement(const std::string& element, const std::string& ) {
- if (element == "hash" && !algo.empty() && !hash.empty()) {
- getPayloadInternal()->setHash(algo, hash);
- algo.clear();
- hash.clear();
+void JingleFileTransferHashParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload());
+ if (info) {
+ getPayloadInternal()->setFileInfo(*info);
+ }
}
}
void JingleFileTransferHashParser::handleCharacterData(const std::string& data) {
- if (!algo.empty()) {
- std::string new_data(data);
- boost::trim(new_data);
- hash += new_data;
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
}
}
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h
index 35e4a05..5a7c6c5 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <Swiften/Elements/JingleFileTransferHash.h>
@@ -20,8 +26,8 @@ public:
virtual void handleCharacterData(const std::string& data);
private:
- std::string algo;
- std::string hash;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
};
}
diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
index cc69348..b3888d6 100644
--- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
+++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
@@ -4,7 +4,13 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
-#include "StreamInitiationFileInfoParser.h"
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h>
#include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
index 8c8601a..a6be599 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
@@ -16,7 +16,7 @@
#include <Swiften/Elements/JingleFileTransferReceived.h>
#include <Swiften/Elements/JingleFileTransferHash.h>
#include <Swiften/Base/DateTime.h>
-
+#include <Swiften/StringCodecs/Base64.h>
#include <Swiften/Base/Log.h>
using namespace Swift;
@@ -36,8 +36,6 @@ class JingleParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testParse_Xep0234_Example5);
CPPUNIT_TEST(testParse_Xep0234_Example8);
CPPUNIT_TEST(testParse_Xep0234_Example10);
- CPPUNIT_TEST(testParse_Xep0234_Example11);
- CPPUNIT_TEST(testParse_Xep0234_Example12);
CPPUNIT_TEST(testParse_Xep0260_Example1);
CPPUNIT_TEST(testParse_Xep0260_Example3);
@@ -223,40 +221,39 @@ class JingleParserTest : public CppUnit::TestFixture {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<jingle xmlns='urn:xmpp:jingle:1'\n"
- " action='session-initiate'\n"
- " initiator='romeo@montague.lit/orchard'\n"
- " sid='851ba2'>\n"
- " <content creator='initiator' name='a-file-offer'>\n"
- " <description xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
- " <offer>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " date='1969-07-21T02:56:15Z'\n"
- " hash='552da749930852c69ae5d2141d3766b1'\n"
- " name='test.txt'\n"
- " size='1022'>\n"
- " <desc>This is a test. If this were a real file...</desc>\n"
- " <range/>\n"
- " </file>\n"
- " </offer>\n"
- " </description>\n"
- " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n"
- " mode='tcp'\n"
- " sid='vj3hs98y'>\n"
- " <candidate cid='hft54dqy'\n"
- " host='192.168.4.1'\n"
- " jid='romeo@montague.lit/orchard'\n"
- " port='5086'\n"
- " priority='8257636'\n"
- " type='direct'/>\n"
- " <candidate cid='hutr46fe'\n"
- " host='24.24.24.1'\n"
- " jid='romeo@montague.lit/orchard'\n"
- " port='5087'\n"
- " priority='8258636'\n"
- " type='direct'/>\n"
- " </transport>\n"
- " </content>\n"
- " </jingle>\n"
+ " action='session-initiate'\n"
+ " initiator='romeo@montague.lit/orchard'\n"
+ " sid='851ba2'>\n"
+ "<content creator='initiator' name='a-file-offer'>\n"
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n"
+ "<file>\n"
+ "<date>1969-07-21T02:56:15Z</date>\n"
+ "<desc>This is a test. If this were a real file...</desc>\n"
+ "<media-type>text/plain</media-type>\n"
+ "<name>test.txt</name>\n"
+ "<range/>\n"
+ "<size>1022</size>\n"
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n"
+ "</file>\n"
+ "</description>\n"
+ "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n"
+ " mode='tcp'\n"
+ " sid='vj3hs98y'>\n"
+ "<candidate cid='hft54dqy'\n"
+ " host='192.168.4.1'\n"
+ " jid='romeo@montague.lit/orchard'\n"
+ " port='5086'\n"
+ " priority='8257636'\n"
+ " type='direct'/>\n"
+ "<candidate cid='hutr46fe'\n"
+ " host='24.24.24.1'\n"
+ " jid='romeo@montague.lit/orchard'\n"
+ " port='5087'\n"
+ " priority='8258636'\n"
+ " type='direct'/>\n"
+ "</transport>\n"
+ "</content>\n"
+ "</jingle>\n"
));
JinglePayload::ref jingle = parser.getPayload<JinglePayload>();
@@ -270,16 +267,15 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>();
-
- std::vector<StreamInitiationFileInfo> offers = description->getOffers();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), offers.size());
- CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName());
- CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash());
- CPPUNIT_ASSERT(1022 == offers[0].getSize());
- CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription());
- CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests());
- CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate());
- CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo());
+ CPPUNIT_ASSERT(description);
+ JingleFileTransferFileInfo fileInfo = description->getFileInfo();
+ CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName());
+ CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first);
+ CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second));
+ CPPUNIT_ASSERT(1022 == fileInfo.getSize());
+ CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription());
+ CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests());
+ CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate());
}
// http://xmpp.org/extensions/xep-0234.html#example-3
@@ -287,22 +283,21 @@ class JingleParserTest : public CppUnit::TestFixture {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<jingle xmlns='urn:xmpp:jingle:1'\n"
- " action='session-accept'\n"
- " initiator='romeo@montague.lit/orchard'\n"
- " sid='851ba2'>\n"
- " <content creator='initiator' name='a-file-offer'>\n"
- " <description xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
- " <offer>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " name='test.txt'\n"
- " size='1022'\n"
- " hash='552da749930852c69ae5d2141d3766b1'\n"
- " date='1969-07-21T02:56:15Z'>\n"
- " <desc>This is a test. If this were a real file...</desc>\n"
- " <range/>\n"
- " </file>\n"
- " </offer>\n"
- " </description>\n"
+ " action='session-accept'\n"
+ " initiator='romeo@montague.lit/orchard'\n"
+ " sid='851ba2'>\n"
+ "<content creator='initiator' name='a-file-offer'>\n"
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n"
+ "<file>\n"
+ "<date>1969-07-21T02:56:15Z</date>\n"
+ "<desc>This is a test. If this were a real file...</desc>\n"
+ "<media-type>text/plain</media-type>\n"
+ "<name>test.txt</name>\n"
+ "<range/>\n"
+ "<size>1022</size>\n"
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n"
+ "</file>\n"
+ "</description>\n"
" <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n"
" mode='tcp'\n"
" sid='vj3hs98y'>\n"
@@ -340,16 +335,16 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>();
+ CPPUNIT_ASSERT(description);
- std::vector<StreamInitiationFileInfo> offers = description->getOffers();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), offers.size());
- CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName());
- CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash());
- CPPUNIT_ASSERT(1022 == offers[0].getSize());
- CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription());
- CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests());
- CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate());
- CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo());
+ JingleFileTransferFileInfo fileInfo = description->getFileInfo();
+ CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName());
+ CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first);
+ CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second));
+ CPPUNIT_ASSERT(1022 == fileInfo.getSize());
+ CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription());
+ CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests());
+ CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate());
}
// http://xmpp.org/extensions/xep-0234.html#example-5
@@ -393,11 +388,9 @@ class JingleParserTest : public CppUnit::TestFixture {
" action='session-info'\n"
" initiator='romeo@montague.lit/orchard'\n"
" sid='a73sjjvkla37jfea'>\n"
- " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
+ " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n"
" <file>\n"
- " <hashes xmlns='urn:xmpp:hashes:0'>\n"
- " <hash algo='sha-1'>552da749930852c69ae5d2141d3766b1</hash>\n"
- " </hashes>\n"
+ " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n"
" </file>\n"
" </checksum>\n"
"</jingle>\n"
@@ -410,12 +403,12 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleFileTransferHash::ref hash = jingle->getPayload<JingleFileTransferHash>();
CPPUNIT_ASSERT(hash);
- CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), hash->getHashes().find("sha-1")->second);
-
+ CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(hash->getFileInfo().getHash("sha-1").get()));
}
// http://xmpp.org/extensions/xep-0234.html#example-10
void testParse_Xep0234_Example10() {
+ Log::setLogLevel(Log::debug);
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<jingle xmlns='urn:xmpp:jingle:1'\n"
@@ -423,13 +416,11 @@ class JingleParserTest : public CppUnit::TestFixture {
" initiator='romeo@montague.lit/orchard'\n"
" sid='uj3b2'>\n"
" <content creator='initiator' name='a-file-request'>\n"
- " <description xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
- " <request>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " hash='552da749930852c69ae5d2141d3766b1'>\n"
- " <range offset='270336'/>\n"
- " </file>\n"
- " </request>\n"
+ " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n"
+ " <file>\n"
+ " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n"
+ " <range offset='270336'/>\n"
+ " </file>\n"
" </description>\n"
" <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n"
" mode='tcp'\n"
@@ -466,101 +457,13 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>();
CPPUNIT_ASSERT(content);
- StreamInitiationFileInfo file = content->getDescription<JingleFileTransferDescription>()->getRequests()[0];
- CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), file.getHash());
- CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long long>(270336), file.getRangeOffset());
+ JingleFileTransferFileInfo file = content->getDescription<JingleFileTransferDescription>()->getFileInfo();
+ CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), file.getHashes().begin()->first);
+ CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(file.getHashes().begin()->second));
+ CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset());
CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests());
}
- // http://xmpp.org/extensions/xep-0234.html#example-11
- void testParse_Xep0234_Example11() {
- PayloadsParserTester parser;
- CPPUNIT_ASSERT(parser.parse(
- "<jingle xmlns='urn:xmpp:jingle:1'\n"
- " action='session-initiate'\n"
- " initiator='romeo@montague.lit/orchard'\n"
- " sid='h2va419i'>\n"
- " <content creator='initiator' name='a-file-offer'>\n"
- " <description xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
- " <offer>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " date='2011-06-01T15:58:15Z'\n"
- " hash='a749930852c69ae5d2141d3766b1552d'\n"
- " name='somefile.txt'\n"
- " size='1234'/>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " date='2011-06-01T15:58:15Z'\n"
- " hash='930852c69ae5d2141d3766b1552da749'\n"
- " name='anotherfile.txt'\n"
- " size='2345'/>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " date='2011-06-01T15:58:15Z'\n"
- " hash='52c69ae5d2141d3766b1552da7499308'\n"
- " name='yetanotherfile.txt'\n"
- " size='3456'/>\n"
- " </offer>\n"
- " </description>\n"
- " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n"
- " mode='tcp'\n"
- " sid='vj3hs98y'>\n"
- " <candidate cid='hft54dqy'\n"
- " host='192.168.4.1'\n"
- " jid='romeo@montague.lit/orchard'\n"
- " port='5086'\n"
- " priority='8257636'\n"
- " type='direct'/>\n"
- " <candidate cid='hutr46fe'\n"
- " host='24.24.24.1'\n"
- " jid='romeo@montague.lit/orchard'\n"
- " port='5087'\n"
- " priority='8258636'\n"
- " type='direct'/>\n"
- " </transport>\n"
- " </content>\n"
- "</jingle>\n"
- ));
-
- JinglePayload::ref jingle = parser.getPayload<JinglePayload>();
- CPPUNIT_ASSERT(jingle);
- CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction());
- CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator());
- CPPUNIT_ASSERT_EQUAL(std::string("h2va419i"), jingle->getSessionID());
-
- JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>();
- CPPUNIT_ASSERT(content);
- CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, content->getCreator());
- CPPUNIT_ASSERT_EQUAL(std::string("a-file-offer"), content->getName());
-
- std::vector<StreamInitiationFileInfo> offers = content->getDescription<JingleFileTransferDescription>()->getOffers();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), offers.size());
- }
-
- // http://xmpp.org/extensions/xep-0234.html#example-12
- void testParse_Xep0234_Example12() {
- PayloadsParserTester parser;
- CPPUNIT_ASSERT(parser.parse(
- "<jingle xmlns='urn:xmpp:jingle:1'\n"
- " action='session-info'\n"
- " initiator='romeo@montague.lit/orchard'\n"
- " sid='a73sjjvkla37jfea'>\n"
- " <received xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n"
- " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n"
- " hash='a749930852c69ae5d2141d3766b1552d'/>\n"
- " </received>\n"
- "</jingle>\n"
- ));
-
- JinglePayload::ref jingle = parser.getPayload<JinglePayload>();
- CPPUNIT_ASSERT(jingle);
- CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction());
- CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator());
- CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID());
-
- boost::shared_ptr<JingleFileTransferReceived> received = jingle->getPayload<JingleFileTransferReceived>();
- CPPUNIT_ASSERT(received);
- CPPUNIT_ASSERT_EQUAL(std::string("a749930852c69ae5d2141d3766b1552d"), received->getFileInfo().getHash());
- }
-
// http://xmpp.org/extensions/xep-0260.html#example-1
void testParse_Xep0260_Example1() {
PayloadsParserTester parser;