/* * Copyright (c) 2012 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include "JingleFileTransferFileInfoParser.h" #include #include #include #include #include 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(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(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; } }