summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp74
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;
+}
+
+}