diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index 32c85a3..8be93c4 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -20,101 +20,101 @@ namespace Swift { StreamInitiationParser::StreamInitiationParser() : level(TopLevel), formParser(0), inFile(false), inFeature(false) { - formParserFactory = new FormParserFactory(); + formParserFactory = new FormParserFactory(); } StreamInitiationParser::~StreamInitiationParser() { - delete formParserFactory; + delete formParserFactory; } void StreamInitiationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - getPayloadInternal()->setID(attributes.getAttribute("id")); - if (!attributes.getAttribute("profile").empty()) { - getPayloadInternal()->setIsFileTransfer(attributes.getAttribute("profile") == FILE_TRANSFER_NS); - } - } - else if (level == PayloadLevel) { - if (element == "file") { - inFile = true; - currentFile = StreamInitiationFileInfo(); - currentFile.setName(attributes.getAttribute("name")); - try { - currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "feature" && ns == FEATURE_NEG_NS) { - inFeature = true; - } - } - else if (level == FileOrFeatureLevel) { - if (inFile && element == "desc") { - currentText.clear(); - } - else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - } + if (level == TopLevel) { + getPayloadInternal()->setID(attributes.getAttribute("id")); + if (!attributes.getAttribute("profile").empty()) { + getPayloadInternal()->setIsFileTransfer(attributes.getAttribute("profile") == FILE_TRANSFER_NS); + } + } + else if (level == PayloadLevel) { + if (element == "file") { + inFile = true; + currentFile = StreamInitiationFileInfo(); + currentFile.setName(attributes.getAttribute("name")); + try { + currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "feature" && ns == FEATURE_NEG_NS) { + inFeature = true; + } + } + else if (level == FileOrFeatureLevel) { + if (inFile && element == "desc") { + currentText.clear(); + } + else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } - ++level; + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } + ++level; } void StreamInitiationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "file") { - getPayloadInternal()->setFileInfo(currentFile); - inFile = false; - } - else if (element == "feature" && ns == FEATURE_NEG_NS) { - inFeature = false; - } - } - else if (level == FileOrFeatureLevel) { - if (inFile && element == "desc") { - currentFile.setDescription(currentText); - } - else if (formParser) { - Form::ref form = formParser->getPayloadInternal(); - if (form) { - FormField::ref field = boost::dynamic_pointer_cast<FormField>(form->getField("stream-method")); - if (field) { - if (form->getType() == Form::FormType) { - foreach (const FormField::Option& option, field->getOptions()) { - getPayloadInternal()->addProvidedMethod(option.value); - } - } - else if (form->getType() == Form::SubmitType) { - if (!field->getValues().empty()) { - getPayloadInternal()->setRequestedMethod(field->getValues()[0]); - } - } - } - } - delete formParser; - formParser = NULL; - } - } + --level; + if (formParser) { + formParser->handleEndElement(element, ns); + } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "file") { + getPayloadInternal()->setFileInfo(currentFile); + inFile = false; + } + else if (element == "feature" && ns == FEATURE_NEG_NS) { + inFeature = false; + } + } + else if (level == FileOrFeatureLevel) { + if (inFile && element == "desc") { + currentFile.setDescription(currentText); + } + else if (formParser) { + Form::ref form = formParser->getPayloadInternal(); + if (form) { + FormField::ref field = boost::dynamic_pointer_cast<FormField>(form->getField("stream-method")); + if (field) { + if (form->getType() == Form::FormType) { + foreach (const FormField::Option& option, field->getOptions()) { + getPayloadInternal()->addProvidedMethod(option.value); + } + } + else if (form->getType() == Form::SubmitType) { + if (!field->getValues().empty()) { + getPayloadInternal()->setRequestedMethod(field->getValues()[0]); + } + } + } + } + delete formParser; + formParser = NULL; + } + } } void StreamInitiationParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } |