/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2015-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include namespace Swift { S5BProxyRequestParser::S5BProxyRequestParser() : parseActivate(false) { } 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")) { std::string host = attributes.getAttributeValue("host").get_value_or(""); unsigned short port = 0; JID jid = attributes.getAttributeValue("jid").get_value_or(""); try { port = boost::numeric_cast(boost::lexical_cast(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; } } void S5BProxyRequestParser::handleCharacterData(const std::string& data) { if (parseActivate) { activateJID = activateJID + data; } } }