diff options
author | Tobias Markmann <tm@ayena.de> | 2012-10-08 21:59:42 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2012-10-08 22:04:15 (GMT) |
commit | 8f75cf3d9892a3ce2c58537f29c851392231e29c (patch) | |
tree | 5239ce98c3e24780ba46d328f383c90cb84b35c7 /Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp | |
parent | 53b7a6ad2d12fc5edc6a98726cabf1ea0b496505 (diff) | |
download | swift-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/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp new file mode 100644 index 0000000..769fc84 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "JingleFileTransferFileInfoParser.h" + +#include <boost/optional.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Base/Log.h> + +#include <cstdio> + +namespace Swift { + +JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) { + +} + +void JingleFileTransferFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 0) { + + } else if (level == 1) { + if (element == "date" || element == "desc" || element == "name" || element == "size") { + cdataBuffer.clear(); + } else if (element == "hash") { + cdataBuffer.clear(); + getPayloadInternal()->setAlgo(attributes.getAttributeValue("algo").get_value_or("md5")); + } else { + if (element == "range") { + int offset = 0; + try { + offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); + } catch (boost::bad_lexical_cast &) { + offset = 0; + } + if (offset == 0) { + getPayloadInternal()->setSupportsRangeRequests(true); + } else { + getPayloadInternal()->setRangeOffset(offset); + } + } + } + } + ++level; +} + +void JingleFileTransferFileInfoParser::handleEndElement(const std::string& element, const std::string&) { + --level; + if (element == "date") { + getPayloadInternal()->setDate(stringToDateTime(cdataBuffer)); + } else if (element == "desc") { + getPayloadInternal()->setDescription(cdataBuffer); + } else if (element == "name") { + getPayloadInternal()->setName(cdataBuffer); + } else if (element == "size") { + try { + getPayloadInternal()->setSize(boost::lexical_cast<boost::uintmax_t>(cdataBuffer)); + } catch (boost::bad_lexical_cast &) { + getPayloadInternal()->setSize(0); + } + } else if (element == "hash") { + getPayloadInternal()->setHash(cdataBuffer); + } +} + +void JingleFileTransferFileInfoParser::handleCharacterData(const std::string& data) { + cdataBuffer += data; +} + +} |