diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp index 6e33f16..7a5a1fd 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp @@ -4,9 +4,16 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "S5BProxyRequestParser.h" +/* + * Copyright (c) 2015-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> #include <boost/lexical_cast.hpp> +#include <boost/numeric/conversion/cast.hpp> #include <boost/optional.hpp> namespace Swift { @@ -18,47 +25,47 @@ S5BProxyRequestParser::~S5BProxyRequestParser() { } void S5BProxyRequestParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (element == "streamhost") { - if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { - HostAddress address = attributes.getAttributeValue("host").get_value_or(""); - int port = -1; - JID jid = attributes.getAttributeValue("jid").get_value_or(""); + if (element == "streamhost") { + if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { + std::string host = attributes.getAttributeValue("host").get_value_or(""); + unsigned short port = 0; + JID jid = attributes.getAttributeValue("jid").get_value_or(""); - try { - port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); - } catch (boost::bad_lexical_cast &) { - port = -1; - } - if (address.isValid() && port != -1 && jid.isValid()) { - S5BProxyRequest::StreamHost streamHost; - streamHost.addressPort = HostAddressPort(address, port); - streamHost.jid = jid; - getPayloadInternal()->setStreamHost(streamHost); - } - } - } else if (element == "activate") { - parseActivate = true; - } else if (element == "query") { - if (attributes.getAttributeValue("sid")) { - getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); - } - } + try { + port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttributeValue("port").get())); + } catch (...) { + } + if (!host.empty() && port != 0 && jid.isValid()) { + S5BProxyRequest::StreamHost streamHost; + streamHost.host = host; + streamHost.port = port; + streamHost.jid = jid; + getPayloadInternal()->setStreamHost(streamHost); + } + } + } else if (element == "activate") { + parseActivate = true; + } else if (element == "query") { + if (attributes.getAttributeValue("sid")) { + getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); + } + } } void S5BProxyRequestParser::handleEndElement(const std::string& element, const std::string&) { - if (element == "activate") { - JID activate = JID(activateJID); - if (activate.isValid()) { - getPayloadInternal()->setActivate(activate); - } - parseActivate = false; - } + if (element == "activate") { + JID activate = JID(activateJID); + if (activate.isValid()) { + getPayloadInternal()->setActivate(activate); + } + parseActivate = false; + } } void S5BProxyRequestParser::handleCharacterData(const std::string& data) { - if (parseActivate) { - activateJID = activateJID + data; - } + if (parseActivate) { + activateJID = activateJID + data; + } } } |