diff options
Diffstat (limited to 'Swiften/StreamStack/XMPPLayer.cpp')
-rw-r--r-- | Swiften/StreamStack/XMPPLayer.cpp | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp index 5fdadf4..982d13f 100644 --- a/Swiften/StreamStack/XMPPLayer.cpp +++ b/Swiften/StreamStack/XMPPLayer.cpp @@ -1,99 +1,101 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/StreamStack/XMPPLayer.h> + +#include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Parser/XMPPParser.h> #include <Swiften/Serializer/XMPPSerializer.h> -#include <Swiften/Elements/ProtocolHeader.h> namespace Swift { XMPPLayer::XMPPLayer( - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - XMLParserFactory* xmlParserFactory, - StreamType streamType, - bool setExplictNSonTopLevelElements) : - payloadParserFactories_(payloadParserFactories), - payloadSerializers_(payloadSerializers), - xmlParserFactory_(xmlParserFactory), - setExplictNSonTopLevelElements_(setExplictNSonTopLevelElements), - resetParserAfterParse_(false), - inParser_(false) { - xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory); - xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType, setExplictNSonTopLevelElements); + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + XMLParserFactory* xmlParserFactory, + StreamType streamType, + bool setExplictNSonTopLevelElements) : + payloadParserFactories_(payloadParserFactories), + payloadSerializers_(payloadSerializers), + xmlParserFactory_(xmlParserFactory), + setExplictNSonTopLevelElements_(setExplictNSonTopLevelElements), + resetParserAfterParse_(false), + inParser_(false) { + xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory); + xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType, setExplictNSonTopLevelElements); } XMPPLayer::~XMPPLayer() { - delete xmppSerializer_; - delete xmppParser_; + delete xmppSerializer_; + delete xmppParser_; } void XMPPLayer::writeHeader(const ProtocolHeader& header) { - writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header))); + writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header))); } void XMPPLayer::writeFooter() { - writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter())); + writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter())); } -void XMPPLayer::writeElement(boost::shared_ptr<ToplevelElement> element) { - writeDataInternal(xmppSerializer_->serializeElement(element)); +void XMPPLayer::writeElement(std::shared_ptr<ToplevelElement> element) { + writeDataInternal(xmppSerializer_->serializeElement(element)); } void XMPPLayer::writeData(const std::string& data) { - writeDataInternal(createSafeByteArray(data)); + writeDataInternal(createSafeByteArray(data)); } void XMPPLayer::writeDataInternal(const SafeByteArray& data) { - onWriteData(data); - writeDataToChildLayer(data); + onWriteData(data); + writeDataToChildLayer(data); } void XMPPLayer::handleDataRead(const SafeByteArray& data) { - onDataRead(data); - inParser_ = true; - // FIXME: Converting to unsafe string. Should be ok, since we don't take passwords - // from the stream in clients. If servers start using this, and require safe storage, - // we need to fix this. - if (!xmppParser_->parse(byteArrayToString(ByteArray(data.begin(), data.end())))) { - inParser_ = false; - onError(); - return; - } - inParser_ = false; - if (resetParserAfterParse_) { - doResetParser(); - } + onDataRead(data); + inParser_ = true; + // FIXME: Converting to unsafe string. Should be ok, since we don't take passwords + // from the stream in clients. If servers start using this, and require safe storage, + // we need to fix this. + if (!xmppParser_->parse(byteArrayToString(ByteArray(data.begin(), data.end())))) { + inParser_ = false; + onError(); + return; + } + inParser_ = false; + if (resetParserAfterParse_) { + doResetParser(); + } } void XMPPLayer::doResetParser() { - delete xmppParser_; - xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_); - resetParserAfterParse_ = false; + delete xmppParser_; + xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_); + resetParserAfterParse_ = false; } void XMPPLayer::handleStreamStart(const ProtocolHeader& header) { - onStreamStart(header); + onStreamStart(header); } -void XMPPLayer::handleElement(boost::shared_ptr<ToplevelElement> stanza) { - onElement(stanza); +void XMPPLayer::handleElement(std::shared_ptr<ToplevelElement> stanza) { + onElement(stanza); } void XMPPLayer::handleStreamEnd() { + onStreamEnd(); } void XMPPLayer::resetParser() { - if (inParser_) { - resetParserAfterParse_ = true; - } - else { - doResetParser(); - } + if (inParser_) { + resetParserAfterParse_ = true; + } + else { + doResetParser(); + } } } |