/* * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include namespace Swift { ClientSessionStanzaChannel::~ClientSessionStanzaChannel() { if (session) { session->onFinished.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); session->onStanzaAcked.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanzaAcked, this, _1)); session->onInitialized.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); session.reset(); } } void ClientSessionStanzaChannel::setSession(std::shared_ptr session) { assert(!this->session); this->session = session; session->onInitialized.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); session->onFinished.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.connect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); session->onStanzaAcked.connect(boost::bind(&ClientSessionStanzaChannel::handleStanzaAcked, this, _1)); } void ClientSessionStanzaChannel::sendIQ(std::shared_ptr iq) { send(iq); } void ClientSessionStanzaChannel::sendMessage(std::shared_ptr message) { send(message); } void ClientSessionStanzaChannel::sendPresence(std::shared_ptr presence) { send(presence); } std::string ClientSessionStanzaChannel::getNewIQID() { return idGenerator.generateID(); } void ClientSessionStanzaChannel::send(std::shared_ptr stanza) { if (!isAvailable()) { SWIFT_LOG(warning) << "Client: Trying to send a stanza while disconnected."; return; } session->sendStanza(stanza); } void ClientSessionStanzaChannel::handleSessionFinished(std::shared_ptr) { session->onFinished.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); session->onStanzaAcked.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanzaAcked, this, _1)); session->onInitialized.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); session.reset(); onAvailableChanged(false); } void ClientSessionStanzaChannel::handleStanza(std::shared_ptr stanza) { std::shared_ptr message = std::dynamic_pointer_cast(stanza); if (message) { onMessageReceived(message); return; } std::shared_ptr presence = std::dynamic_pointer_cast(stanza); if (presence) { onPresenceReceived(presence); return; } std::shared_ptr iq = std::dynamic_pointer_cast(stanza); if (iq) { onIQReceived(iq); return; } } bool ClientSessionStanzaChannel::getStreamManagementEnabled() const { if (session) { return session->getStreamManagementEnabled(); } return false; } std::vector ClientSessionStanzaChannel::getPeerCertificateChain() const { if (session) { return session->getPeerCertificateChain(); } return std::vector(); } void ClientSessionStanzaChannel::handleStanzaAcked(std::shared_ptr stanza) { onStanzaAcked(stanza); } void ClientSessionStanzaChannel::handleSessionInitialized() { onAvailableChanged(true); } }