summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2014-12-17 15:21:30 (GMT)
committerSwift Review <review@swift.im>2015-02-03 10:03:17 (GMT)
commitb5fc240f1cf4e340e04177a23cb8cf827b9ca16b (patch)
tree13d701e160af328553551974e55fea876d21eed8 /Swiften/Elements
parentd860805af76ec85e003bf3019407bbb7acd218c9 (diff)
downloadswift-b5fc240f1cf4e340e04177a23cb8cf827b9ca16b.zip
swift-b5fc240f1cf4e340e04177a23cb8cf827b9ca16b.tar.bz2
Update Jingle FT protocol to namespace verison urn:xmpp:jingle:apps:file-transfer:4.
Test-Information: Adjusted unit tests and successfully build/run them on OS X 10.9.5. Change-Id: I63789e3fb351999f719157b54fa9fcf95f40fb07
Diffstat (limited to 'Swiften/Elements')
-rw-r--r--Swiften/Elements/HashElement.h42
-rw-r--r--Swiften/Elements/JingleFileTransferDescription.h24
-rw-r--r--Swiften/Elements/JingleFileTransferFileInfo.h120
-rw-r--r--Swiften/Elements/JingleFileTransferHash.h19
4 files changed, 181 insertions, 24 deletions
diff --git a/Swiften/Elements/HashElement.h b/Swiften/Elements/HashElement.h
new file mode 100644
index 0000000..44d2f96
--- /dev/null
+++ b/Swiften/Elements/HashElement.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/ByteArray.h>
+
+namespace Swift {
+ /*
+ * @brief This class represents a XEP-0300 <hash/> element.
+ */
+ class HashElement {
+ public:
+ HashElement(const std::string& algorithm, const ByteArray& hash) : algorithm_(algorithm), hash_(hash) {
+ }
+
+ void setHashValue(const std::string& algorithm, const ByteArray& hash) {
+ algorithm_ = algorithm;
+ hash_ = hash;
+ }
+
+ const std::string& getAlgorithm() const {
+ return algorithm_;
+ }
+
+ const ByteArray& getHashValue() const {
+ return hash_;
+ }
+
+ bool operator==(const HashElement& rhs) const {
+ return (algorithm_ == rhs.algorithm_) && (hash_ == rhs.hash_);
+ }
+
+
+ private:
+ std::string algorithm_;
+ ByteArray hash_;
+ };
+}
diff --git a/Swiften/Elements/JingleFileTransferDescription.h b/Swiften/Elements/JingleFileTransferDescription.h
index 620f8f5..9308abf 100644
--- a/Swiften/Elements/JingleFileTransferDescription.h
+++ b/Swiften/Elements/JingleFileTransferDescription.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Isode Limited.
+ * Copyright (c) 2011-2014 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -10,32 +10,22 @@
#include <vector>
#include <Swiften/Elements/JingleDescription.h>
-#include <Swiften/Elements/StreamInitiationFileInfo.h>
+#include <Swiften/Elements/JingleFileTransferFileInfo.h>
namespace Swift {
class JingleFileTransferDescription : public JingleDescription {
public:
typedef boost::shared_ptr<JingleFileTransferDescription> ref;
- void addOffer(const StreamInitiationFileInfo& offer) {
- offers.push_back(offer);
+ void setFileInfo(const JingleFileTransferFileInfo& fileInfo) {
+ fileInfo_ = fileInfo;
}
-
- const std::vector<StreamInitiationFileInfo>& getOffers() const {
- return offers;
- }
-
- void addRequest(const StreamInitiationFileInfo& request) {
- reqeusts.push_back(request);
- }
-
- const std::vector<StreamInitiationFileInfo>& getRequests() const {
- return reqeusts;
+ const JingleFileTransferFileInfo& getFileInfo() {
+ return fileInfo_;
}
private:
- std::vector<StreamInitiationFileInfo> offers;
- std::vector<StreamInitiationFileInfo> reqeusts;
+ JingleFileTransferFileInfo fileInfo_;
};
}
diff --git a/Swiften/Elements/JingleFileTransferFileInfo.h b/Swiften/Elements/JingleFileTransferFileInfo.h
new file mode 100644
index 0000000..8fec59e
--- /dev/null
+++ b/Swiften/Elements/JingleFileTransferFileInfo.h
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+#include <map>
+
+#include <boost/optional.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+#include <Swiften/Elements/HashElement.h>
+#include <Swiften/Elements/Payload.h>
+
+namespace Swift {
+
+ /**
+ * @brief This class represents the file info used in XEP-0234.
+ */
+ class JingleFileTransferFileInfo : public Payload {
+ typedef boost::shared_ptr<JingleFileTransferFileInfo> ref;
+
+ public:
+ JingleFileTransferFileInfo(const std::string& name = "", const std::string& description = "", unsigned long long size = 0, const boost::posix_time::ptime &date = boost::posix_time::ptime()) :
+ name_(name), description_(description), size_(size), date_(date), supportsRangeRequests_(false), rangeOffset_(0) {
+ }
+
+ public:
+ typedef std::map<std::string, ByteArray> HashElementMap;
+
+ public:
+ void setName(const std::string& name) {
+ name_ = name;;
+ }
+
+ const std::string& getName() const {
+ return name_;
+ }
+
+ void setDescription(const std::string& description) {
+ description_ = description;
+ }
+
+ const std::string& getDescription() const {
+ return description_;
+ }
+
+ void setMediaType(const std::string& mediaType) {
+ mediaType_ = mediaType;
+ }
+
+ const std::string& getMediaType() const {
+ return mediaType_;
+ }
+
+ void setSize(const boost::uintmax_t size) {
+ size_ = size;
+ }
+
+ boost::uintmax_t getSize() const {
+ return size_;
+ }
+
+ void setDate(const boost::posix_time::ptime& date) {
+ date_ = date;
+ }
+
+ const boost::posix_time::ptime& getDate() const {
+ return date_;
+ }
+
+ void setSupportsRangeRequests(const bool supportsIt) {
+ supportsRangeRequests_ = supportsIt;
+ }
+
+ bool getSupportsRangeRequests() const {
+ return supportsRangeRequests_;
+ }
+
+ void setRangeOffset(const boost::uintmax_t offset) {
+ supportsRangeRequests_ = true;
+ rangeOffset_ = offset;
+ }
+
+ boost::uintmax_t getRangeOffset() const {
+ return rangeOffset_;
+ }
+
+ void addHash(const HashElement& hash) {
+ hashes_[hash.getAlgorithm()] = hash.getHashValue();
+ }
+
+ const std::map<std::string, ByteArray>& getHashes() const {
+ return hashes_;
+ }
+
+ boost::optional<ByteArray> getHash(const std::string& algorithm) const {
+ boost::optional<ByteArray> ret;
+ if (hashes_.find(algorithm) != hashes_.end()) {
+ ret = boost::optional<ByteArray>(hashes_.find(algorithm)->second);
+ }
+ return ret;
+ }
+
+ private:
+ std::string name_;
+ std::string description_;
+ std::string mediaType_;
+ boost::uintmax_t size_;
+ boost::posix_time::ptime date_;
+ bool supportsRangeRequests_;
+ boost::uintmax_t rangeOffset_;
+ HashElementMap hashes_;
+ };
+}
diff --git a/Swiften/Elements/JingleFileTransferHash.h b/Swiften/Elements/JingleFileTransferHash.h
index 5603531..d34e35d 100644
--- a/Swiften/Elements/JingleFileTransferHash.h
+++ b/Swiften/Elements/JingleFileTransferHash.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 <boost/shared_ptr.hpp>
@@ -11,25 +17,24 @@
#include <string>
#include <Swiften/Elements/JingleDescription.h>
+#include <Swiften/Elements/JingleFileTransferFileInfo.h>
namespace Swift {
class JingleFileTransferHash : public Payload {
public:
- typedef std::map<std::string, std::string> HashesMap;
-public:
typedef boost::shared_ptr<JingleFileTransferHash> ref;
- void setHash(const std::string& algo, const std::string& hash) {
- hashes[algo] = hash;
+ void setFileInfo(const JingleFileTransferFileInfo& fileInfo) {
+ fileInfo_ = fileInfo;
}
- const HashesMap& getHashes() const {
- return hashes;
+ JingleFileTransferFileInfo& getFileInfo() {
+ return fileInfo_;
}
private:
- HashesMap hashes;
+ JingleFileTransferFileInfo fileInfo_;
};
}