diff options
Diffstat (limited to 'Swiften/Elements')
-rw-r--r-- | Swiften/Elements/HashElement.h | 42 | ||||
-rw-r--r-- | Swiften/Elements/JingleFileTransferDescription.h | 24 | ||||
-rw-r--r-- | Swiften/Elements/JingleFileTransferFileInfo.h | 120 | ||||
-rw-r--r-- | Swiften/Elements/JingleFileTransferHash.h | 19 |
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_; }; } |